This guide covers the step-by-step process of installing Kubernetes using the kubeadm utility. kubeadm is a tool recommended for bootstrapping a Kubernetes cluster. We will use 3 nodes: a master node and 2 worker nodes. The nodes will run on AWS EC2 instances with Ubuntu 20.04 LTS (t2.medium instance type, 8GB storage). You can use any cloud provider to launch the instances.
Prerequisites
Infrastructure Requirements:
- Instance Type: t2.medium or better.
- Storage: 8GB minimum.
- Operating System: Ubuntu 20.04 LTS.
- Network: Ensure all nodes are in the same VPC with required ports opened.
Tools:
- SSH client (e.g., ssh or PuTTY).
- curl, vi or nano (pre-installed in Ubuntu).
Required Ports: (Ensure these are allowed in the security group)
These ports are required for the Kubernetes cluster to work. Check the
Worker Nodes:
- TCP: 10256 (Kube Proxy)
- TCP: 30000-32767 (NodePort Services)
- TCP: 10250 (Kubelet API)
- TCP: 22 (SSH)
- ICMP: (Ping Connection)
2. Connect to Instances and Set Hostnames
Setting a hostname ensures each node has a unique identifier, simplifying management and troubleshooting.
Master Node
ssh -i "key-pair-name.pem" ubuntu@master-node-ip
hostnamectl set-hostname master
4. Disable Swap memory on all nodes
Kubernetes requires swap to be disabled to ensure proper memory allocation for containers.
Temporary (until reboot)
sudo swapoff -a
Permanent
sudo sed -i.bak '/ swap / s/^/#/' /etc/fstab
Apply sysctl params without reboot
sudo sysctl --system
6. Install Container Runtime (Containerd)
Downloads and extracts containerd, which is a lightweight and efficient container runtime for Kubernetes.
curl -LO https://github.com/containerd/containerd/releases/download/v2.0.0/containerd-2.0.0-linux-amd64.tar.gz
sudo tar Cxzvf /usr/local containerd-2.0.0-linux-amd64.tar.gz
Set SystemdCgroup to true in runc.options
This configuration change enables the use of systemd cgroups for managing the resources and lifecycle of containers in the containerd runtime, which can potentially improve performance and reliability.
- Open the
/etc/containerd/ config.tomlfile using thevitext editor:
sudo vi /etc/containerd/config.toml
Navigate to the
plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc.optionssection of the configuration file.Add the following line to this section:
plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc.options
SystemdCgroup = true
Install Runc Runtime
Downloads and installs the runc runtime, a lightweight and efficient container runtime for Kubernetes. Runc is required by Containerd to manage and run containers based on OCI specifications.
curl -LO https://github.com/opencontainers/runc/releases/download/v1.2.2/runc.amd64
sudo install -m 755 runc.amd64 /usr/local/sbin/runc
7. Install Kubeadm, Kubelet and Kubectl.
Installs Kubernetes tools like kubeadm, kubelet, and kubectl, which are essential for managing and deploying Kubernetes clusters.
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Verify Kubeadm, Kubelet and Kubectl
kubeadm version
kubelet --version
kubectl version --client
8. Setup Kubernetes Cluster
Bootstraps the master node, specifying the network CIDR and the API server's address.
Master Node
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=<private_ip_of_master_node> --node-name master
Install Calico CNI on Master Node
Deploys Calico as the network plugin for Kubernetes, enabling pod communication across the cluster.
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/tigera-operator.yaml
curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/custom-resources.yaml
kubectl apply -f custom-resources.yaml
Generate a token for worker nodes and run the output command on worker nodes
kubeadm token create --print-join-command
Output should be similar to this:
kubeadm join 10.0.0.10:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
List all the nodes in the cluster
After successfully joining the worker nodes to the cluster, list the nodes in the cluster.
kubectl get nodes
Nginx Page in the Browser
Notes
Troubleshooting:
- Use kubectl describe node for node issues.
- Use kubectl logs for pod issues.
- Verify CNI installation using kubectl get pods -n kube-system.
Next Steps:
- Monitor the cluster using tools like Prometheus.
- Scale up the cluster with additional worker nodes.
Conclusion
Congratulations! 🎉 You've successfully deployed a Kubernetes cluster using kubeadm and set up a sample Nginx application to validate your setup. This guide has walked you through every step, from preparing your nodes to launching your first pod. With your Kubernetes cluster up and running, you're now ready to explore the endless possibilities it offers, from deploying scalable applications to experimenting with advanced concepts like autoscaling, monitoring, and service meshes.

SOCIAL SHARE CARD GENERATOR