Kubernetes is a powerful open-source platform for automating deployment, scaling, and management of containerized applications. Installing Kubernetes on a VPS allows you to manage and scale applications seamlessly. In this guide, we’ll cover the steps for setting up a Kubernetes single-node cluster on a VPS with AnonVM.
System Requirements
Before starting, ensure your server meets the following prerequisites:
- OS: Ubuntu 20.04+ or CentOS 7+
- CPU: Minimum 2 vCPUs (recommended 4)
- RAM: 2GB+ (recommended 4GB)
- Access: Root or sudo privileges
Step 1: Update and Configure Your System
Begin by updating your package list and upgrading any outdated packages:
Ensure the swap memory is turned off, as Kubernetes does not support it:
To make this change permanent, edit the /etc/fstab
file and comment out any lines related to swap:
Step 2: Install Docker
Kubernetes requires a container runtime, and Docker is one of the most commonly used options.
Install Docker on Ubuntu
-
Install necessary packages:
-
Add Docker’s official GPG key:
-
Add the Docker repository:
-
Install Docker:
Install Docker on CentOS
-
Install Docker:
-
Start Docker:
Step 3: Install Kubernetes Components
You will need three key Kubernetes components: kubeadm
, kubelet
, and kubectl
.
-
Add Kubernetes Repository:
For CentOS:
-
Install Kubernetes Components:
-
Start and Enable kubelet:
Step 4: Initialize the Kubernetes Cluster
Now that Docker and Kubernetes components are installed, you can initialize the Kubernetes cluster. Run the following command as a root or sudo user:
Take note of the kubeadm join
command output, as you’ll need it to add more nodes to the cluster in the future.
Step 5: Set Up kubeconfig for Rootless Access
To use kubectl
as a non-root user, you need to set up a kubeconfig
file.
-
Create the .kube directory:
-
Verify the Cluster Status:
You should see the master node listed as
Ready
.
Step 6: Install a Pod Network Add-On
To allow communication between Kubernetes nodes, you need to set up a network add-on. A common choice is Flannel.
-
Deploy Flannel:
-
Verify Network Pods:
You should see Flannel-related pods running in the kube-system
namespace.
Step 7: Deploy a Test Application
To verify that Kubernetes is working correctly, deploy a sample application.
-
Create a Nginx Deployment:
-
Expose the Deployment:
-
Retrieve the Node Port:
The output will show the port Kubernetes assigned. Access the Nginx server by navigating to <your-server-ip>:<NodePort>
in your browser.
Step 8: Enable Kubernetes Dashboard (Optional)
The Kubernetes Dashboard is a web-based user interface to manage Kubernetes resources.
-
Apply Dashboard YAML:
-
Create an Admin User:
Create an admin user to log into the Dashboard by defining an admin service account and cluster role binding.
-
Retrieve Dashboard Access Token:
Copy the token, then access the Dashboard by navigating to https://<your-server-ip>:6443/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
.
Conclusion
You’ve now set up a Kubernetes single-node cluster on your VPS with AnonVM! This environment is ideal for development, testing, and learning Kubernetes concepts. As your project grows, you can expand by adding more nodes. Remember to keep your Kubernetes installation updated and practice secure cluster management.