Kubernetes (K8s) is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. Installing K8s requires tools to simplify and accelerate the process. This article explains how to install K8s using the most common tool, Kubeadm.
K8s Installation Workflow
The following is the general workflow for installing K8s using Kubeadm:
| Step | Description |
|---|---|
| 1 | Install Docker |
| 2 | Install kubeadm, kubelet, and kubectl |
| 3 | Configure the Master node |
| 4 | Initialize the Master node |
| 5 | Join Worker nodes |
| 6 | Verify the cluster |
Below we detail each step with the required commands.
Step 1: Install Docker
First, install Docker as the container runtime for Kubernetes. Use the following commands:
sudo apt-get update
sudo apt-get install -y docker.io
Step 2: Install kubeadm, kubelet, and kubectl
Install the three Kubernetes tools: kubeadm, kubelet, and kubectl.
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
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 Worker nodes to join the cluster:
sudo kubeadm token generate
Save this token for later use. Then initialize the Master node with a pod network CIDR:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
This command initializes the Master and outputs important information, including the command to join Worker nodes. Save this output.
Step 4: Initialize the Master Node
Set up the kubeconfig file 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
Install a network plugin for pod communication. Here we use Flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Step 5: Join Worker Nodes
Use the join command saved from the Master initialization to add Worker nodes. The command format is:
sudo kubeadm join IP:PORT --token <token> --discovery-token-ca-cert-hash sha256:<certificate-hash>
Replace IP:PORT, <token>, and <certificate-hash> with the actual values from the Master output.
Step 6: Verify the Cluster
Check the cluster status:
kubectl get nodes
kubectl get pods --all-namespaces
If everything is correct, all nodes should show Ready and all pods should be running.
The Kubernetes cluster installation is now complete.
Summary
This article detailed the steps to install Kubernetes using Kubeadm, providing command examples. We hope this helps beginners understand the installation process and successfully set up their own Kubernetes cluster.