Skip to content

Priyanka-987/kubernetes-installation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 

Repository files navigation

Kubernetes Cluster Installation Lab

Objective

Deploy a Kubernetes cluster using kubeadm, containerd, and Calico.

Environment

  • Ubuntu
  • Kubernetes
  • Containerd
  • Calico

Architecture

            +----------------+
            |  Control Plane |
            | kube-apiserver |
            | etcd           |
            | scheduler      |
            +--------+-------+
                     |
       ----------------------------
       |                          |
+------+-------+          +------+-------+
| Worker Node1 |          | Worker Node2 |
| kubelet      |          | kubelet      |
| containerd   |          | containerd   |
+------+-------+          +------+-------+
       |                          |
       +------------+-------------+
                    |
             +------+------+
             |   Calico    |
             |   Network   |
             +-------------+

Installation Steps

Setup

  1. 4 VMs Ubuntu 22.04 — 1 control plane, 3 worker nodes.
  2. Static IPs assigned to each VM.
  3. /etc/hosts updated with hostname → IP mappings for all nodes.
  4. Swap disabled on all nodes.

SSH into control plane:

ssh priyanka@my-ubuntu-1

Number 0 to Number 4 need to be applied on control plane and workers


0. Disable Swap

sudo swapoff -a
sudo vi /etc/fstab

Remove any swap entries.


1. Install Required Packages

Load kernel modules:

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

System settings:

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
sudo sysctl --system

2. Install containerd

sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml

Edit containerd config to use systemd cgroups:

sudo sed -i 's/            SystemdCgroup = false/            SystemdCgroup = true/' /etc/containerd/config.toml

Verify:

grep 'SystemdCgroup = true' /etc/containerd/config.toml

Restart:

sudo systemctl restart containerd
sudo systemctl enable containerd

3. Install Kubernetes Components

Add repository:

sudo apt update && sudo apt-get install -y apt-transport-https ca-certificates curl gpg conntrack
sudo 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

Update and check versions:

sudo apt-get update
apt-cache policy kubelet | head -n 20

Install Kubernetes:

VERSION=1.31.14-1.1
sudo apt-get install -y kubelet=$VERSION kubeadm=$VERSION kubectl=$VERSION
sudo apt-mark hold kubelet kubeadm kubectl containerd
sudo systemctl enable --now kubelet

4. Check Services

sudo systemctl status kubelet.service
sudo systemctl status containerd.service

kubelet will show inactive (dead) until cluster is initialized with kubeadm init or joined with kubeadm join.


5. Creating the Kubernetes Cluster

Log into the control plane:

ssh priyanka@my-ubuntu-1

Download Calico manifest:

wget https://raw.githubusercontent.com/projectcalico/calico/master/manifests/calico.yaml

Edit Pod CIDR if needed:

vi calico.yaml

Initialize the cluster:

sudo kubeadm init --kubernetes-version v1.31.14

Set up kubeconfig:

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

6. Deploy Pod Network (Calico)

Apply Calico:

kubectl apply -f calico.yaml

Watch pods:

kubectl get pods --all-namespaces --watch

Check when all system pods are Running:

kubectl get pods --all-namespaces

Check nodes:

kubectl get nodes

7. Join Worker Nodes to the Cluster

Log out of the worker node and return to the control plane:

exit

Generate the cluster join command:

kubeadm token create --print-join-command

Copy the output — you'll need it for each worker node.

SSH into the first worker node:

ssh priyanka@my-ubuntu-2

Run the join command (example — your token will differ):

sudo kubeadm join <CONTROL_PLANE_IP>:6443 \
  --token <TOKEN> \
  --discovery-token-ca-cert-hash sha256:<HASH>

Return to control plane:

exit

Validation

Check node status (will be NotReady until network pod is deployed):

kubectl get nodes

Watch pods across all namespaces:

kubectl get pods --all-namespaces

Screenshot Name

Verify worker node becomes Ready:

kubectl get nodes

Screenshot Name

Troubleshooting

Issue 1: Worker Node Not Joining

Cause: Firewall ports were blocked.

Resolution: Required Kubernetes ports were opened and the join command was executed again.

Issue 2: Calico Pods Not Starting

Cause: Network configuration mismatch.

Resolution: Re-applied Calico manifest and verified pod status.

Lessons Learned

  • Understanding of Kubernetes cluster architecture.
  • Experience with kubeadm-based installation.
  • Familiarity with containerd runtime configuration.
  • Improved troubleshooting skills for node and networking issues.
  • Better understanding of Kubernetes networking using Calico.

Project Outcome

Successfully deployed a Kubernetes cluster using kubeadm and containerd with Calico networking. Verified node readiness, system pod health, and cluster networking functionality.

Releases

No releases published

Packages

 
 
 

Contributors