How to Join a Worker Node to a Kubernetes Cluster
Once you’ve set up your Kubernetes control plane (master node), the next step is to add worker nodes to your cluster. Worker nodes are where your applications and workloads will run. In this guide, we’ll walk you through the process of joining a worker node to your Kubernetes cluster.
Prerequisites
- Control Plane Node:
- A fully initialized Kubernetes control plane (using
kubeadm init
). - The
kubeadm join
command from the control plane output.
- Worker Node:
- Ubuntu installed (same version as the control plane).
- Docker or containerd installed and configured.
kubeadm
,kubelet
, andkubectl
installed (same version as the control plane).
Step 1: Prepare the Worker Node
Before joining the worker node, ensure it meets the following requirements:
1. Disable Swap
Kubernetes requires swap to be disabled:
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
2. Install Container Runtime
Install Docker or containerd (same as the control plane). For example, to install containerd:
sudo apt update
sudo apt install -y containerd
sudo systemctl enable --now containerd
3. Install Kubernetes Tools
Install kubeadm
, kubelet
, and kubectl
(ensure the versions match the control plane):
sudo apt update
sudo apt install -y kubeadm kubelet kubectl
sudo apt-mark hold kubeadm kubelet kubectl
Step 2: Join the Worker Node
Use the kubeadm join
command generated during the control plane initialization.
1. Retrieve the Join Command
On the control plane node, retrieve the kubeadm join
command:
kubeadm token create --print-join-command
This will output a command like:
kubeadm join <control-plane-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
2. Run the Join Command on the Worker Node
On the worker node, run the kubeadm join
command:
sudo kubeadm join <control-plane-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Example:
sudo kubeadm join 192.168.1.100:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
Step 3: Verify the Worker Node
After joining the worker node, verify its status from the control plane.
1. Check Node Status
On the control plane node, run:
kubectl get nodes
The worker node should appear in the list with a NotReady
status initially. After a few minutes, it should transition to Ready
.
2. Check Pods on the Worker Node
Verify that the CNI plugin (e.g., Flannel, Calico) is running on the worker node:
kubectl get pods -n kube-system -o wide
You should see CNI-related pods (e.g., kube-flannel-ds-*
) running on the worker node.
Troubleshooting
If the worker node doesn’t join successfully, check the following:
1. Token Expired
If the token has expired, generate a new one on the control plane:
kubeadm token create --print-join-command
2. Network Issues
- Ensure the worker node can reach the control plane on port
6443
. - Check firewall rules to allow traffic between nodes.
3. CNI Plugin Not Installed
If the worker node stays in NotReady
state, ensure the CNI plugin is installed:
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
4. Kubelet Logs
Check the kubelet
logs on the worker node for errors:
sudo journalctl -u kubelet -f
Conclusion
Joining a worker node to a Kubernetes cluster is a simple process using the kubeadm join
command. By ensuring your worker node meets the prerequisites and running the join command, you can scale your cluster to handle more workloads.
Next Steps:
- Add more worker nodes to scale your cluster.
- Deploy applications and monitor their performance using tools like
kubectl
andkubectl top
.
For more details, refer to the official Kubernetes documentation. Happy clustering! 🚀