Chirag's Technology Tutorial
*********************************************************************************
* Kubernetes (K8s) Install and Configure on Ubuntu 24.04 LTS (1 Master and 1 Worker) *
*********************************************************************************
YouTube Video:
To install and configure Kubernetes on your system, follow the steps below for setting up both the master and worker nodes:
Prerequisites:
Master Node IP: 192.168.224.131
Worker Node IP: 192.168.224.132
Ubuntu 24.04 LTS installed on both nodes
Both nodes should be able to communicate with each other (ensure no firewalls block the ports used by Kubernetes)
Step 1: Install Docker (On Both Nodes) (192.168.224.131 and 192.168.224.132)
Kubernetes requires a container runtime; Docker is commonly used.
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
Verify that Docker is installed correctly.
sudo docker --version
Output:
Docker version 24.0.7, build 24.0.7-0ubuntu4
Step 2: Configure Docker Cgroup Driver (On Both Nodes) (192.168.224.131 and 192.168.224.132)
Ensure Docker uses systemd as the cgroup driver to align with Kubernetes requirements.
Create or edit Docker daemon configuration:
sudo nano /etc/docker/daemon.json
Add the following content:
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
Restart Docker:
sudo systemctl restart docker
Step 3: Install Kubernetes Packages (On Both Nodes) (192.168.224.131 and 192.168.224.132)
Install the Kubernetes components: kubeadm, kubelet, and kubectl on all nodes.
Add the Kubernetes APT repository:
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
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Note: Replace v1.31 with latest version. Check the official release page.
Install the Kubernetes components:
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
Hold the packages at their current version to prevent automatic upgrades:
sudo apt-mark hold kubelet kubeadm kubectl
Step 4: Disable Swap all Nodes (192.168.224.131 and 192.168.224.132)
Kubernetes requires swap to be disabled. Disable swap on all nodes.
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Step 5: Initialize the Master Node (192.168.224.131)
On the master node, initialize the Kubernetes cluster with kubeadm.
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
After initialization, you'll see a join command. Copy this command as it will be used to join worker nodes to the cluster.
Your Kubernetes control-plane has initialized successfully!
Copy the last command starts with kubeadm join, we need to join worker nodes. This command need to run in worker nodes.
Step 6: Configure kubectl for the Master Node (192.168.224.131)
Set up the kubeconfig file for the root user on the master node.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Verify the cluster status.
kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
svr1 NotReady control-plane 91s v1.31.2
Step 7: Install a Pod Network Add-on on Master node (192.168.224.131)
Install a pod network so that your pods can communicate with each other. We'll use Flannel for this example.
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Verify that all nodes are up and running.
kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
svr1 NotReady control-plane 4m24s v1.31.2
Step 8: Join Worker Nodes to the Cluster Worker Node (192.168.224.132)
On each worker node, use the join command obtained from the master node initialization step. The command will look something like this:
kubeadm join 192.168.224.131:6443 --token 3w1bxq.08805jfg131q0v4o \
--discovery-token-ca-cert-hash sha256:20a4ab2ebaf6ae686c95e35c2790d78e4be2173f008b07606f09ab6afc73b2d1
Verify that the nodes have joined the cluster. Execute following command in master node.
kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
svr1 Ready control-plane 2m10s v1.31.2
svr2 NotReady <none> 12s v1.31.2
Step 9: (Optional) Configure kubectl for a Non-Root User
If you want to configure kubectl for a non-root user, run the following commands:
sudo -i
mkdir -p /home/<your-username>/.kube
cp -i /etc/kubernetes/admin.conf /home/<your-username>/.kube/config
chown <your-username>:<your-username> /home/<your-username>/.kube/config
exit
Step 10: Deploy a Test Application on Master node (192.168.224.131)
Deploy a simple Nginx application to verify that your Kubernetes cluster is working correctly.
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
(Optional) Disable the firewall or add ports in firewall
In this step, we can disable the firewall for temporary or we can add the node port and Nginx ports in firewall
Get the NodePort assigned to the Nginx service.
kubectl get svc
Output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3m24s
nginx NodePort 10.109.206.194 <none> 80:30120/TCP 6s
You should be able to access the Nginx application by visiting
http://<node-ip>:<node-port> in your web browser.
http://192.168.224.131:30120
Note: Replace <node-ip> with your worker node and you can get the <node-port>. In the previous command output, the node port is 30120.
Check in console:
root@svr1:/home/dept# curl http://10.97.237.27
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@svr1:/home/dept#
Conclusion
We've explored the installation and configuration of Kubernetes (K8s) on Ubuntu 24.04. With this foundation, you can scale your cluster by adding more worker nodes, deploy more sophisticated applications, and dive into the rich ecosystem of Kubernetes tools and extensions. For production environments, consider implementing high availability, persistent storage, and other best practices to ensure a robust and resilient Kubernetes setup.
For any doubts and query, please write on YouTube video comments section.
Note : Flow the Process shown in video.
Please, Subscribe and like for more videos:
https://www.youtube.com/@chiragstutorial
Don't forget to, Follow, Like, Share &, Comment
Thanks & Regards,
Chitt Ranjan Mahto "Chirag"
_____________________________________________________________________
Note: All scripts used in this demo will be available in our website.
Link will be available in description.
#chirags
#chiragstutorial
#chiragsTechnologytutorial
#chiragsTechnologytutorials
#Technologytutorial
#Technology
#Technologycourse
chirags, chirags tutorial, chirags Technology tutorial, chirags Technology tutorial, Kubernetes (K8s) Install and Configure on Ubuntu 24.04 LTS (1 Master and 1 Worker)