Step By Step Guide on Kubeadm

Step By Step Guide on Kubeadm

Step 1: Prepare Your Environment

Before you begin, ensure that you have at least two or more Linux-based machines (physical or virtual) with the following prerequisites:

  • A compatible Linux distribution (Ubuntu, CentOS, etc.)

  • Docker installed on all nodes

  • Swap disabled (you can do this by running swapoff -a and removing swap entries from /etc/fstab)

  • Firewall rules open for necessary ports (e.g., port 6443 for Kubernetes API)

Step 2: Install kubeadm, kubelet, and kubectl

You'll need to install kubeadm, kubelet, and kubectl on all your cluster nodes. Use your package manager (e.g., apt for Ubuntu, yum for CentOS) to install these components. For example, on Ubuntu:

shellCopy codesudo apt update
sudo apt install -y kubelet kubeadm kubectl

Step 3: Initialize the Master Node

Choose one of your nodes to be the master node. On that node, initialize the Kubernetes control plane using kubeadm. Run this command:

shellCopy codesudo kubeadm init --pod-network-cidr=10.244.0.0/16

This command initializes the master node and provides you with a command to run on worker nodes to join them to the cluster.

Step 4: Configure kubectl

After initializing the master node, kubeadm will provide you with a command to configure kubectl on your local machine. It's essential to run this command to be able to interact with the cluster from your local terminal.

Step 5: Install a Pod Network Add-on (Optional)

For pods to communicate with each other across nodes, you need to install a network plugin. A popular choice is Calico. Install it using kubectl:

shellCopy codekubectl apply -f https://docs.projectcalico.org/v3.19/manifests/calico.yaml

Step 6: Join Worker Nodes

On each worker node, run the kubeadm join command provided by the kubeadm init output from the master node. It typically looks like this:

shellCopy codesudo kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

This command joins the worker node to the Kubernetes cluster.

Step 7: Verify Cluster Setup

Back on the master node, you can verify the cluster's status by running:

shellCopy codekubectl get nodes

You should see all nodes (including the master) in the "Ready" state.

Step 8: Deploy Applications

With your cluster up and running, you can use kubectl to deploy applications and manage your Kubernetes resources.

Conclusion

You've successfully set up a basic Kubernetes cluster using kubeadm. From here, you can explore more advanced configurations, add-ons, and application deployments within your cluster.

Did you find this article valuable?

Support Aditya Sahai by becoming a sponsor. Any amount is appreciated!