
This article provides a guide for how to deploy Kubernetes cluster on Ubuntu VPS.
What is a Kubernetes Cluster?
Before you deploy Kubernetes cluster on Ubuntu VPS, it’s important to understand Kubernetes clusters.
A Kubernetes cluster is a set of machines (nodes) that work together to run and manage containerized applications at scale. Kubernetes, an open-source container orchestration platform, automates deployment, scaling, and operations of application containers across a cluster of hosts.
Key Components of a Kubernetes Cluster:
- Master Node (Control Plane)
- Manages the cluster and makes global decisions.
- Includes:
- API Server – Exposes Kubernetes API for communication.
- Scheduler – Assigns workloads (pods) to worker nodes.
- Controller Manager – Ensures the cluster state matches the desired state.
- etcd – A distributed key-value store for cluster configuration.
- Worker Nodes
- Run the containerized applications.
- Includes:
- Kubelet – Manages communication between the node and the master.
- Container Runtime – Runs containers (e.g., Docker, containerd).
- Kube Proxy – Manages networking for services.
- Pods
- The smallest deployable unit in Kubernetes.
- Contains one or more containers that share storage and networking.
- Services
- Expose applications to the network and manage load balancing.
- Ingress
- Manages external access to services.
How Kubernetes Clusters Work
- The control plane schedules and manages workloads.
- The worker nodes execute workloads (containers) in pods.
- Networking and storage are abstracted to allow seamless scaling.
- Kubernetes automates deployment, scaling, and failover.
Why Use a Kubernetes Cluster?
- Scalability – Automatically scales applications.
- High Availability – Ensures apps run even if nodes fail.
- Portability – Works across cloud and on-prem environments.
- Resource Efficiency – Optimizes hardware utilization.
How to Deploy Kubernetes Cluster on Ubuntu VPS
Deploying a Kubernetes cluster on a fresh Ubuntu VPS involves a series of steps, from setting up the prerequisites to initializing the cluster and adding nodes. This guide will walk you through deploying a single-node Kubernetes cluster using kubeadm, which is a popular tool that simplifies the process.
Prerequisites
- Ubuntu VPS Setup: You should start with a fresh install of Ubuntu 20.04 LTS on your VPS. This guide assumes you have root access to your VPS.
- Hardware Requirements:
- CPU: 2 cores or more
- Memory: 2GB RAM or more
- Storage: 20GB or more of free disk space
- Network: Full network connectivity between all machines in the cluster
- Install Required Packages:
- Curl
- apt-transport-https
- Software Properties (optional, for adding repositories if needed)
-
Prepare Your VPS
SSH into Your Server: Use a terminal or SSH client to connect to your VPS:
ssh username@your_vps_ip
Update and Upgrade the System:
sudo apt update && sudo apt upgrade -y
Disable Swap:
Kubernetes does not support swap. Check if swap is enabled:sudo swapon --show
If it is, disable it:
sudo swapoff -a
Then comment out or remove the swap line from
/etc/fstab
to prevent swap from enabling on reboot. -
Install Docker
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt update sudo apt install docker-ce -y sudo systemctl start docker sudo systemctl enable docker
-
Install Kubernetes Components
Add Kubernetes Repository:
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt update
Install Kubernetes Tools:
sudo apt install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
-
Configure sysctl Settings
Enable IP Forwarding:
echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf echo "net.bridge.bridge-nf-call-ip6tables=1" | sudo tee -a /etc/sysctl.conf sudo sysctl --system
-
Initialize the Kubernetes Cluster
Initialize Kubernetes:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
This command will output some instructions. Follow them as a regular user:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
-
Deploy Pod Network
Install a CNI Plugin like Flannel:
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
-
Verify the Installation
Check Nodes:
kubectl get nodes
Check Pods in kube-system Namespace:
kubectl get pods --all-namespaces
-
Taint Removal (for single node clusters)
If you’re running on a single node, you might want to remove the master node’s taint to allow pods to run there:
kubectl taint nodes --all node-role.kubernetes.io/master-
-
Additional Configuration
Dashboard (Optional): For a UI to manage your cluster:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
Then, you’ll need to set up access to the dashboard, which involves creating a service account and setting up a kubeconfig.
Persistent Storage (Optional): If you need persistent volumes, you might want to install something like nfs-provisioner or use local-path provisioner.
Troubleshooting Tips:
Logs: Use journalctl -xeu kubelet
or kubectl logs -n kube-system
for logs.
Networking: Check if pods can communicate by creating test pods and pinging each other.
Remember, this setup is for a basic Kubernetes cluster on a single node. For production, consider multi-node setups, high availability, and security configurations like RBAC, network policies, and regular updates.
Additional Configuration (Optional)
- Allow workloads on the master node (since this is a single-node cluster):
kubectl taint nodes --all node-role.kubernetes.io/master-
- Install Helm (a Kubernetes package manager):
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Conclusion
You now have a basic Kubernetes cluster running on a single Ubuntu VPS. From here, you can deploy applications, scale your cluster, or add additional nodes if needed. This setup is ideal for development, testing, or small production environments.
You now know how to deploy Kubernetes cluster on Ubuntu VPS server.
[…] that can be highly effective for monitoring specific services like Apache, MySQL, Docker, Kubernetes, and […]