How to setup Kubernetes cluster over cloud on Ubuntu OS

Let's learn together and serve the society, Make India Proud.
Search for a command to run...

Let's learn together and serve the society, Make India Proud.
No comments yet. Be the first to comment.
Kubernetes, or K8s, is a system for managing containerized apps in a clustered environment. It provides efficient ways of managing distributed components across various infrastructures.
💡 Taking inspiration from and dedicated to our training guru, Shri Maninder sir. Hey everyone! In this article, we'll learn how to set up a Kubernetes (k8s) cluster on a Linux CentOS 7 machine. You can do this either on cloud servers or virtual ma...
How Real Teams Deploy to Production: Kubernetes Deployment Strategies

Hello, this is Rakesh Kumar — your DevOps project practice trainer and your friend.I’m back again with a brilliant DevOps project that is not only production-ready but also highly valuable for real-world learning. This project is designed to take you...

Introduction If you are learning DevOps, you may be asking yourself: 👉 “I already know Bash scripting. Do I really need Python? Can’t I do the same work with Bash?” This is a common question, and the truth is: No, you don’t always need Python – Bas...

Project Idea – Build Your Own Mini Shell

Why every DevOps engineer needs Python in their toolkit

Embarking on your Kubernetes cloud cluster journey for practice may seem daunting, but fear not. We're here to walk you through the process, step by step, as you set up a Kubernetes cluster on the Ubuntu OS in the cloud.
I am taking here AWS instances t2.medium, ubuntu OS, 20 GB storage each, Firewall security Allows ALL traffic, and swap memory disabled. I will go with three nodes cluster (1 Master + 2 Worker Node) with the same above configuration.
| Instance Type | Configuration | Storage |
| T2.medium or higher | 2vC Core + 4 GB RAM or more | 20 GB or more |
We are going to create a new user admin (If there is not) and assign sudoers privileges to him. so for this we create a new folder under /etc/sudoers.d/admin, and do the below entry in /etc/sudoers.d/admin. Dont forget to restart sshd service
$ sudo adduser admin
$ sudo echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/admin
$ sudo systemctl restart sshd
Change the Hostname of each machine using hostnamectll command.
Machine (Public_IP) Machine (Private_IP) Hostname 52.168.32.71 172.25.32.32 masternode.example.com 52.168.23.28 172.35.32.64 workernode1.example.com 52.168.23.28 172.25.64.63 workernode2.example.com
$ sudo hostnamectl set-hostname <your-hostname>
$ sudo exec bash # execute the current shell with latest changes
$ hostname
$ sudo vi /etc/hosts
172.25.32.32 masternode.example.com
172.35.32.64 workernode1.example.com
172.25.64.63 workernode2.example.com
Note: Ping all machines to each other
In /etc/ssh/sshd_config file uncomment and allow the following lines.
$ sudo vi /etc/ssh/sshd_config
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
And restart sshd service
$ sudo systemctl restart sshd
$ sudo systemctl enable sshd
Generate an SSH key and distribute it to your worker node instances for secure and efficient communication. This step involves creating an SSH key and seamlessly deploying it across your worker node instances to streamline the communication process.
$ ssh-keygen
$ ssh-copyid workernode1.example.com
$ ssh-copyid workernode2.example.com
$ sudo swapoff -a
$ sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
$ sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
$ sudo modprobe overlay
$ sudo modprobe br_netfilter
$ sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
$ sudo sysctl --system
$ sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update
$ sudo apt install -y containerd.io
$ containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
$ sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
$ sudo systemctl restart containerd
$ sudo systemctl enable containerd
Add Repository for kubernetes
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/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.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Install kubelet, kubectl, kubeadm
$ sudo apt update
$ sudo apt install -y kubelet kubeadm kubectl
$ sudo apt-mark hold kubelet kubeadm kubectl
$ sudo kubeadm init --control-plane-endpoint=<your-master-node-hostname>
NOTE: on master node with the admin user. and check status of 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
# To check either cluster is setup being proper setup or not, and how many nodes are connected yet.
# Also check that kubernetes resources is proper installed or not.
$ kubectl get nodes -o wide
$ kubectl get pods -n kube-system
$ kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml
$ sudo kubeadm join masternode.example.net:6443 --token vt3ua6.scma2y8rl4menfh2 \
--discovery-token-ca-cert-hash sha256:049xaa7fcdced8a8e7b20d37ec0c5dd699ds5f8x616885697q2ff917d4c94962a36
$ kubectl create -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml
$ kubectl expose deployment nginx-deployment --name=my-svc --port=80 --target-port=80 --type=NodePort
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-svc NodePort 10.100.124.129 <none> 80:32567/TCP 2m
<Public-IP-of-any-of-nodes>:32567
Deployment documentation:- https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
Download MobaXterm for your windows machine to get ssh over cloud instances:- https://mobaxterm.mobatek.net/download.html