Mentor and Source of Learning:
Mr. Babar Zahoor : OpenSourceEducation.net
میرے یوٹیوب چینل پراس مشق کی وڈیو ملاحظہ فرمائیے۔
You can watch the whole exercise on my youtube channel.
A Little Talking about Kubernetes
Welcome to my comprehensive and practical guide on the installation and deployment of 2-node Kubernetes cluster using Kubeadm in Ubuntu 20.04.
Kubernetes is an open-source platform, it is also called with name K8s and has become the de facto standard for container orchestration, it enables organizations to efficiently manage and scale their applications.
The Kubeadm, a tool designed to simplify the process of setting up a Kubernetes cluster, you can quickly get started with your own cluster deployment using kubeadm.
In this blog post, you will walk through a detailed, step-by-step process of installing and configuring a 2-node Kubernetes cluster using Kubeadm on Ubuntu 20.04 based Desktop PC.
Especially for the beginners, if you are a beginner exploring Kubernetes for the first time, this guide is here to assist you.
Before diving into the installation process, let’s take a bird’s eye view of its key components.
Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It organizes containers into logical units called “pods,” which are the basic building blocks of Kubernetes deployments.
Kubeadm, on the other hand, is a command-line tool (CLI Tool) that simplifies the process of bootstrapping a Kubernetes cluster.
It handles:
– initialization of the control plane
– joins worker nodes to the cluster
– configures the necessary components for communication and coordination
between nodes.
By leveraging Kubeadm and Calico Trigera, you can effortlessly set up a Kubernetes cluster without the need for laborious manual configuration.
After having a short introduction to K8s, let’s discuss the prerequisites for setting up this Kubernetes cluster. Before diving into the installation process, there are a few requirements you need to fulfill to ensure a smooth deployment. Here are the key prerequisites:
1. Ubuntu 20.04:
Ensure that you have a machine or virtual environment running Ubuntu 20.04 as the operating system. This guide is specifically tailored for Ubuntu 20.04, so make sure you have it installed.
2.Sufficient Resources:
Check that your system meets the minimum resource requirements for running a Kubernetes cluster. This includes an adequate amount of CPU(s), memory (RAM), and storage (HardDisk space) to handle the workload you plan to run on the cluster.
3. Network Connectivity:
Ensure that your machine has a stable internet connection. This is crucial for downloading necessary packages, container images, and accessing Kubernetes resources during the installation process.
4. Root Privileges:
You will need administrative privileges or root access to execute commands and make system-level changes during the installation and configuration process. Make sure you have the necessary permissions to perform these tasks.
By meeting these prerequisites, you will be well-prepared to proceed with the installation and deployment of your 2-node Kubernetes cluster using Kubeadm and Calico Tigera.
Now, let’s dive into the installation and deployment process of a 2-node Kubernetes cluster using Kubeadm on Ubuntu 20.04. Follow along, and soon you’ll have a fully functional Kubernetes cluster up and running, ready to power your containerized applications.
Ubuntu 20.04 میں Kubeadm کا استعمال کرتے ہوئے دو نوڈ 2-Node Kubernetes کلسٹر کی تنصیب یعنی انسٹالیشن اور تعیناتی/ ڈِپلائمنٹ سے متعلق میری جامع اور عملی گائیڈ میں خوش آمدید۔
Kubernetes ایک اوپن سورس پلیٹ فارم ہے، اسے K8s کے نام سے بھی پکارا جاتا ہے اور یہ کنٹینر آرکیسٹریشن کے لئے ڈی فیکٹو سٹینڈرڈ بن گیا ہے، یہ اداروں کو اپنی ایپلی کیشنز کو مؤثر طریقے سے منظم کرنے کے قابل بناتا ہے۔
Kubeadm ایک ٹول ہےجسے Kubernetes کلسٹر قائم کرنے کے عمل کو آسان بنانے کے لیے ڈیزائن کیا گیا ہے۔ آپ kubeadm کا استعمال کرتے ہوئے اپنے کلسٹر کو بڑی آسانی اور تھوڑے وقت میں ڈپلائے کرنا شروع کر سکتے ہیں۔
اس بلاگ پوسٹ میں، آپ اُبُنٹُو آپریٹنگ سسٹم والے ڈیسک ٹاپ پی سی پر Kubeadm کا استعمال کرتے ہوئے کیوبرنیٹس کے 2 نوڈکلسٹر کو انسٹال اور کانفیگر کرنے کے تفصیلی اور مرحلہ وار عمل سے گزریں گے۔
خاص طور پر نئے سیکھنے والوں کے لیے، اگر آپ پہلی بار کیوبرنیٹس کادورہ کرنے والے ہیں، تو یہ گائیڈ آپ کی مدد کے لیے حاضر ہے۔
تنصیب یعنی انسٹالیشن کے عمل میں غوطہ لگانے سے پہلے، آئیے اس میں شامل کلیدی اجزاء پر ایک طائرانہ نظر ڈالتے ہیں۔
Kubernetes ایک اوپن سورس کنٹینر آرکیسٹریشن پلیٹ فارم ہے۔ جو کنٹینرائزڈ ایپلی کیشنز کی تعیناتی/ ڈپلائمنٹ، اسکیلنگ اور انتظام کو خودکار بناتا ہے۔ یہ کنٹینرز کو منطقی اکائیوں(logical units) میں ترتیب دیتا ہے جنہیں “pods” کہتے ہیں، جو Kubernetes کی تعیناتیوں /ڈپلائمنٹس کے بنیادی تعمیراتی بلاکس ہیں۔
دوسری طرف Kubeadm ایک کمانڈ لائن ٹول (CLI Tool ) ہے۔ جو Kubernetes کلسٹر کو بوٹسٹریپ کرنے کے عمل کو آسان بناتا ہے۔
یہ سنبھالتا ہے:
– کنٹرول پلین کی ابتدائی ترتیب
– کارکن /ورکرنوڈ زکو کلسٹر میں شامل کرتا ہے۔
– نوڈز کے مابین مواصلات /کمیونیکیشن اور ہم آہنگی کے لئے ضروری اجزاء کو تشکیل دیتا ہے۔
Kubeadm اور Calico Trigera کا فائدہ اٹھا تے ہوئے، آپ آسانی سے بغیر کسی عملی مشقت کے آسانی سے Kubernetes کلسٹر قائم کر سکتے ہیں۔
K8s سے مختصر تعارف کرانے کے بعد، آئیے اس Kubernetes کلسٹر کو ترتیب دینے کے لیے بنیادی ضروریات پر بات کرتے ہیں۔ تنصیب کے عمل میں غوطہ لگانے سے پہلے، تعیناتی/ ڈپلائےمنٹ کوسادااورآسان بنانے کے لیے آپ کو چند تقاضے پورے کرنے کی ضرورت ہے۔وہ چند کلیدی شرائط یہ ہیں:
1. Ubuntu 20.04:
یقینی بنائیں کہ آپ کے پاس جو مشین یا ورچوئل انوائرنمنٹ ہے جس پر Ubuntu 20.04 آپریٹنگ سسٹم کے طور پر چل رہا ہے۔ یہ گائیڈ خاص طور پر Ubuntu 20.04 کے لیے تیار کیا گیا ہے، اس لیے یقینی بنائیں کہ آپ نے اسے انسٹال کر لیا ہے۔
2. کافی وسائل:
چیک کریں کہ آپ کا سسٹم Kubernetes کلسٹر چلانے کے لیے کم از کم وسائل کی ضروریات کو پورا کرتا ہے۔ اس میں CPU(s)، میموری (RAM)، اور اسٹوریج (HardDisk space) کی مناسب مقدار شامل ہے ۔تاکہ آپ کلسٹر پر جو کام کرنے والے ہیں اس کے بوجھ کو سنبھال سکے۔
3. انٹرنیٹ سے کنکشن:
یقینی بنائیں کہ آپ کی مشین کا انٹرنیٹ کنکشن مستحکم ہے۔ یہ ضروری پیکجز، کنٹینر امیجز کو ڈاؤن لوڈ کرنے اور انسٹالیشن کے عمل کے دوران Kubernetes کےوسائل تک رسائی کے لیے بہت اہم ہے۔
4. رُوٹ پرمشنز/مراعات:
آپ کو کمانڈ پر عمل درآمد کرنے اور انسٹالیشن اور کانفیگریشن کے عمل کے دوران سسٹم کی سطح پر تبدیلیاں کرنے کے لیے انتظامی مراعات/ ایڈمنسٹریٹؤ پریولیجز یا رُوٹ رسائی یعنی رُوٹ ایکسَیس کی ضرورت ہوگی۔ یقینی بنائیں کہ آپ کے پاس ان کاموں کو انجام دینے کے لیے ضروری اجازتیں ہیں۔
ان شرائط کو پورا کرنے سے، آپ Kubeadm اور Calico Tigera کا استعمال کرتے ہوئے اپنے Kubernetesکے Two node کلسٹر کی تنصیب/انسٹالیشن اور تعیناتی/ڈپلائمنٹ کے لئے عمل کو آگے بڑھانے کے لیے اچھی طرح سے تیار ہو جائیں گے۔
اب، آئیے Ubuntu 20.04 پر Kubeadm کا استعمال کرتے ہوئے دو نوڈز والے Kubernetes کلسٹر کی تنصیب اور تعیناتی کے عمل میں غوطہ لگاتے ہیں۔ ساتھ چلیں، اور جلد ہی آپ کے پاس مکمل طور پر فعال Kubernetes کلسٹر چل رہا ہوگا، جو آپ کی کنٹینرائزڈ ایپلی کیشنز کی میزبانی کے لیے تیار ہے۔
1.
Swap and Firewall should be Turned-Off
Run these command on each machine!
Swap is the space of hard disk to support RAM. In case RAM got loaded and no space left the system then uses the Hard Disk space as RAM.
ان کمانڈوں کو کلسٹر کی ہر مشین پر چلائیں!
سویپ RAM کو سپورٹ کرنے کے لیے ہارڈ ڈسک کے اوپر جگہ ہے۔ اگر RAM لوڈ ہو جائے اور سسٹم میں کوئی جگہ نہ رہ جائے ،تو سسٹم ہارڈ ڈسک کی جگہ کو بطور RAM استعمال کرتا ہے۔
sudo swapoff -a
sudo systemctl disable firewalld
Disabling The Swap
Mark the swap partition entry line with “#” to ‘comment’.
سوَیپ پارٹیشن کی سیٹنگز والی لائن کو”#” سے کمنٹ لائن مارک کردیں۔
sudo nano /etc/fstab
OR directly use the following command to do it:
یا مندرجہ ذیل کمانڈ سے بلاواسطہ یہ کام کر لیں۔
sudo sed -i '/ swap / s/^/#/' /etc/fstab
Enabling Ping by-Name
Do This on Each Machine!
Edit the hosts file in /etc directory and add the following information about each machine.
اس عمل کو کلسٹر کی ہر مشین پر دوہرائیں!
ہر مشین کی etc/ ڈائریکٹری میں موجود “ھاسٹس” hosts نام کی فائل میں اپنی ہر مشین کا آئی پی ایڈریس اور نام درج کریں۔
IP address machine name
:
IP n n machine
In my case it is:
میرے سیٹ اپ میں یہ کچھ ایسے ہے:
192.168.10.11 3tKmaster192.168.10.14 3tKworker1 Now, Restart The Machine!
اب مشین کو ریسٹارٹ کریں!
2.
Before Installing Kubeadm
Some prerequisites are needed to get on track.
کیوب ایڈیئیم کی انسٹالیشن سے پہلے کچھ بنیادی کام کرنے ضروری ہیں۔
Configuring The IPv4 bridge
Run This Command on Each Machine!
Loading 2 modules and making them available on Reboots.
اس کمانڈ کو ہر مشین پر چلائیں!
یہ کمانڈان دو ماڈیولز کو ایسے لوڈ اور ایکٹوکرے گی کہ “سسٹم ری-بوٹ” پر دستیاب ہوں۔
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
Confirm if overlay modules are loaded.
ان کمانڈ وں سے اس بات کی تسلی ہوجائیگی کہ “اؤور لے ماڈیولز” لوڈ ہوچکے ہیں۔
sudo modprobe overlay
sudo modprove br_netfilter
3.
Configuring the needed sysctl parameters.
Run This Command on Each Machine!
The needed parameters of sysctl are configured Persistent around system reboots.
اس کمانڈ کو کلسٹرکی ہر مشین پر چلائیں!
سیس سی ٹی ایل کے ضرورت کے پیرامیٹرز کو مشین ری-بُوٹ پر مستقلاً دستیاب بنانے کے لئےیہ کمانڈ چلائیں گے۔
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
Following command applied sysctl parameters in current env. without Restart.
مندرجہ ذیل کمانڈ سے سیس-سی-ٹی-ایل کے پیرامیٹرزموجودہ سیٹ اپ میں بغیرسسٹم رِیسٹارٹ کے لگا دیئے گئے۔
sudo sysctl --system
4.
Installing Docker
Do This on Each Machine!
Always update the system before installing any package.
مندرجہ ذیل عمل ہر مشین پر دوہرائیں!
ہمیشہ کوئی بھی نیا پیکیج/ایپلیکیشن انسٹال کرنے سے پہلے سسٹم کو اپڈیٹ ضرور کریں۔
sudo apt-get update
sudo apt install docker.io
Checking version of docker.
ڈاکر کاورژن دیکھنے کے لئے ۔
docker --version
Enabling Docker on Reboots.
ڈاکر کی دستیابی کو سسٹم ری-بوٹس پر ممکن بنانے کے لئے ۔
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker
5.
Installing Packages, Initially Required by Kubernetes.
Run This Command on Each Machine!
اس کمانڈ کو کلسٹر کی ہر مشین پر چلائیں!
sudo apt-get update
sudo apt install apt-transport-https ca-certificates curl -y
6.
Downloading the Google Cloud Public Keys.
Run This Command on Each Machine!
اس کمانڈ کو کلسٹرکی ہر مشین پر چلائیں!
First need to create the directory for the keyrings.
کی رنگز کے لئے پہلے سب ڈائریکٹری بنانی ہے۔
sudo mkdir /etc/apt/keyrings
Following command will download the keys.
مندرجہ ذیل کمانڈ کیز کو ڈاؤنلوڈ کرے گی۔
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg
7.
Adding/Enabling the Kubernetes apt repository.
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
To view the official documentation about the process:
If you feel like to dive deeper to know more, and you should!
Goto:kubernetes.io/docs/home/
and search for Kubeadm and
-pick-
– Installing kubeadm
-Creating cluster with kubeadm
اگر آپ سمجھتے ہیں کہ آپ کو مزید اس کے بارے میں جاننا چاہیئے، بلکہ ضرور جانیئے۔
اس کے لئے دیئے گئے آفیشل لنک پر ڈاکومنٹیشن پیج پر آپ کو یہ سب معلومات ملیں گی۔
8.
Installing Kubeadm
Run This Command on Each Machine!
اس کمانڈ کو کلسٹرکی ہر مشین پر چلائیں!
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
Creating and Configuring The Cluster
sudo Kubeadm init
Kubeadm config images pull
Kubectl Normal User Setup on Master Only.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
9.
Initializing Kubernetes on Master
At the completion of the process of following command the kubeadm join message will appear. Copy paster of take notes of this whole message, and we will be using this to join the worker nodes to the cluster.
کیوب ایڈیئیم جائن کمانڈکے پراسیس کے مکمل ہونے پر ایک میسیج سکرین پر آئے گا۔ اس میسیج کو نوٹ کرلیں یا کاپی پیسٹ کرکے رکھ لیں، اس کے ذریعے ہم نے آگے چل کر ورکر نوڈز کوکلسٹرمیں شامل کرنا ہے۔
Should be Typed on the Master Node’s command line:
sudo kubeadm init - -ignore-preflight-errors=all - -pod-network-cidr=192.168.0.0/16
Kubectl get nodes
Kubectl get pods -A
To keep the packages from getting Auto-updates:
Run This Command on Each Machine!
اس کمانڈ کو کلسٹرکی ہر مشین پر چلائیں!
sudo apt-mark hold kubeadm kubelet kubectl
10.
Installing Calico Networking/SDN (The Overlay Network)
A Pod Network to Cluster Deployment allows Nodes in a cluster to communicate with each other.
کلسٹرڈپلائمنٹ میں پاڈ نیٹ ورک نوڈز کو اس قابل بناتا ہے کہ وہ کلسٹر میں دیگر نوڈز کے ساتھ رابطہ کر سکیں۔
Creating Tigera Operator:
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml
Custom resources downloaded to configure Calico:
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/custom-resources.yaml -O
Applying the settings in .yaml file:
kubectl apply -f custom-resources.yaml
Kubectl get po -A