This guide will walk you through the stages of installing a Kubernetes cluster with multiple worker nodes on Ubuntu using Docker as the container runtime and Calico as the network plugin. You'll also use Kubernetes to launch a dummy Nginx application.
Update and Upgrade:
Update the package list and upgrade existing packages:
sudo apt update
sudo apt upgrade -y
Disable Swap
Disable swap and update /etc/fstab:
sudo swapoff -a sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Install Docker
Run the following commands on each machine (master and workers):
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
Start and Enable Docker:
Enable and start the Docker service:
sudo systemctl start docker
sudo systemctl enable docker
Install Kubernetes
Run the following commands on each machine (master and workers):
sudo apt-get update
sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
Create the Kubernetes Cluster
Initialize the Master Node:
SSH into the master node.
Initialize the Kubernetes control plane and set the Pod network CIDR:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
Configure kube config and Calico:
On the master node, copy the kubeconfig file and set permissions:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo
chown $(id -u):$(id -g) $HOME/.kube/config
Deploy the Calico network plugin:
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml
Join Worker Nodes:
SSH into each worker node and run the kubeadm join command provided by the master initialization output.
Deploy a Dummy Application
Create a Deployment YAML file (e.g., dummy-deployment.yaml):
apiVersion: apps/v1
kind: Deployment
metadata:
name: dummy-deployment
spec:
replicas: 3
selector:
matchLabels:
app: dummy-app
template:
metadata:
labels:
app: dummy-app
spec:
containers:
- name: nginx
image: nginx:latest
Apply the Deployment:
Apply the deployment configuration:
kubectl apply -f dummy-deployment.yaml
Verify the Deployment and Pods:
Check the status of the deployment and the created pods:
kubectl get deployments
kubectl get pods
Your Kubernetes cluster is ready. I have used the most basic configuration for creating the cluster.
For more details on creating the cluster, refer to the Kubernetes documentation.