This article provides a guide for how to deploy Kubernetes cluster on Ubuntu VPS.
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)
Step 1: Update and Upgrade Ubuntu Packages
Ensure your system is up-to-date with the latest packages and security patches.
sudo apt update && sudo apt upgrade -y sudo apt install -y curl apt-transport-https software-properties-common
Step 2: Install Docker
Kubernetes requires a container runtime, and Docker is a popular choice.
- Install Docker:
sudo apt install docker.io -y
- Start and Enable Docker:
sudo systemctl start docker sudo systemctl enable docker
- Add your user to the Docker group (optional):
sudo usermod -aG docker $USER newgrp docker
Step 3: Install Kubernetes Components
You need to install kubeadm, kubelet, and kubectl.
- Add the Kubernetes Signing Key:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- Add Kubernetes to the Repository List:
echo "deb https://apt.kubernetes.io/ kubernetes-focal main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
- Update and Install Kubernetes Components:
sudo apt update sudo apt install kubeadm kubelet kubectl -y sudo apt-mark hold kubeadm kubelet kubectl
Step 4: Initialize the Kubernetes Cluster
Use kubeadm to initialize the cluster:
- Initialize Cluster:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Note: The CIDR block may vary depending on the network plugin you choose.
- Set Up Local kubeconfig:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 5: Deploy a Pod Network
A network plugin is necessary for Pods to communicate with each other.
- Install Flannel (as an example of a network plugin):
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Step 6: Verify Installation
Check the status of the node and ensure that everything is running correctly.
kubectl get nodes
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.
[…] that can be highly effective for monitoring specific services like Apache, MySQL, Docker, Kubernetes, and […]