Installation Overview
Kubernetes (commonly referred to as K8s) is an open-source platform for orchestraitng containerized applications. This guide deomnstrates how to install Kubernetes using Kubeadm, a widely adopted tool for setting up K8s clusters.
The general installation process involves the following steps:
| Step | Description |
|---|---|
| Step 1 | Install Docker |
| Step 2 | Install Kubeadm, Kubelet, and Kubectl |
| Step 3 | Configure the Master Node |
| Step 4 | Initialize the Master Node |
| Step 5 | Add Worker Nodes to the Cluster |
| Step 6 | Verify Cluster Functionality |
Step 1: Install Docker
Docker serves as the container runtime for Kubernetes. Install Docker using the following commands:
sudo apt-get update
sudo apt-get install docker.io
Step 2: Install Kubeadm, Kubelet, and Kubectl
These three tools are essential for cluster management and node operations. Use the following commands to install them:
sudo apt-get update && sudo apt-get install -y apt-transport-https
sudo 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
sudo apt-mark hold kubelet kubeadm kubectl
Step 3: Configure the Master Node
Generate a token for future worker node joining:
sudo kubeadm token generate
Save the token for later use.
Initialize the master node using this command:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Step 4: Finalize Master Node Setup
Configure Kubernetes access for the current 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 a network plugin to enable communication between Pods. The Flannel plugin can be installed using:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Step 5: Add Worker Nodes
Use the join command provided during the master node initiallization to add worker nodes. The format of the command is:
sudo kubeadm join IP:PORT --token TOKEN --discovery-token-ca-cert-hash sha256:HASH
Replace IP, PORT, TOKEN, and HASH with values obtained during the master node setup.
Step 6: Validate Cluster Operation
Check the status of nodes and Pods to confirm the cluster is functioning correctly:
kubectl get nodes
kubectl get pods --all-namespaces
Ensure that all nodes show a Ready status and all Pods are running.