Installing Kubernetes: Steps, Commands, and Worker Node Configuration

Kubernetes, the container orchestration platform, offers a robust solution for deploying, managing, and scaling containerized applications. In this guide, we’ll walk through the steps to install Kubernetes, including the essential commands and the configuration of both master and worker nodes.

1. Prerequisites:

Ensure your system meets the following prerequisites:

  • Linux Distribution: Ubuntu 20.04 (or a compatible distribution).
  • Docker: Install the latest version of Docker on both master and worker nodes.
  • Swap: Disable swap on your system.
  • Kubelet, Kubectl, and Kubeadm: Install these Kubernetes components on both master and worker nodes.

2. Master Node Installation:

a. Initialize Kubernetes Master:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

b. Set Up Kubectl 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

c. Apply Pod Network:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

3. Worker Node Installation:

a. Install Docker on Worker Node:

sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker

b. Join Worker Node to Cluster:

Use the kubeadm join command provided at the end of kubeadm init on the worker node.

sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>

c. Set Up Kubectl for the Worker Node:

Copy the kubectl configuration from the master node.

mkdir -p $HOME/.kube
scp <username>@<master-node-ip>:/etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

4. Verification:

a. Check Nodes:

kubectl get nodes

b. Check Pods:

kubectl get pods --all-namespaces

5. Common Troubleshooting:

a. Networking Issues:

If pods are not communicating, check the network plugin applied during kubectl apply.

b. Node Not Ready:

Ensure that the worker node successfully joined the cluster. Use kubectl describe node <node-name> for details.

c. Reset Kubernetes:

To reset the cluster (on both master and worker nodes):

sudo kubeadm reset

6. Optional Add-ons:

a. Dashboard Installation:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml

b. Metrics Server Installation:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Conclusion:

Congratulations! You’ve successfully installed Kubernetes on a master node and added a worker node to your cluster. Docker and Kubernetes components are now set up on both master and worker nodes. Use these steps as a foundation to explore and deploy containerized applications in your Kubernetes environment.

Happy Kuberneting!