DEV Community

V A I S H A L i
V A I S H A L i

Posted on

Setting Up a Kubernetes Cluster Using Kubeadm

Introduction

Kubeadm is a powerful tool that simplifies Kubernetes cluster setup. It is designed to provide best-practice defaults while ensuring a secure and production-ready environment. In this guide, we will walk through setting up a Kubernetes cluster using Kubeadm, address common pitfalls, and provide next steps for deploying workloads.

Prerequisites

Before you begin, ensure that you have:

  • At least two Linux machines (one master, one or more nodes) running Ubuntu 22.04 or CentOS 8.
  • A minimum of 2 CPUs, 2GB RAM per node, and 20GB disk space.
  • A non-root user with sudo privileges.
  • Container runtime (Docker, containerd, or CRI-O).
  • Network connectivity between nodes.
  • Disabled swap: sudo swapoff -a.

Installation Steps

Step 1: Install Dependencies

On all nodes, install required packages:

sudo apt update && sudo apt install -y apt-transport-https curl
curl -fsSL 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 update
sudo apt install -y kubelet kubeadm kubectl
sudo systemctl enable kubelet && sudo systemctl start kubelet
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize the Control Plane (Master Node)

sudo kubeadm init --pod-network-cidr=192.168.0.0/16
Enter fullscreen mode Exit fullscreen mode

After initialization, set up kubectl for the non-root user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Enter fullscreen mode Exit fullscreen mode

Step 3: Deploy a Pod Network

Choose a networking solution such as Calico or Flannel. For example, to install Calico:

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: Join Worker Nodes

Retrieve the join command from the master:

kubeadm token create --print-join-command
Enter fullscreen mode Exit fullscreen mode

Run the output command on each worker node.

Step 5: Verify the Cluster

Check the nodes and pods:

kubectl get nodes
kubectl get pods --all-namespaces
Enter fullscreen mode Exit fullscreen mode

Common Pitfalls & Fixes

Issue Solution
kubeadm init fails due to swap enabled Run sudo swapoff -a and remove swap entries from /etc/fstab.
Worker nodes show NotReady status Ensure the network plugin is installed and kube-proxy is running.
kubectl commands fail Check if the KUBECONFIG environment variable is set correctly.

Next Steps

  • Deploy a sample application: Kubernetes Deployment Guide
  • Learn about RBAC and security best practices.
  • Set up monitoring using Prometheus and Grafana.

By following this guide, you should now have a functional Kubernetes cluster using Kubeadm. 🚀

Top comments (0)