Introduction: Kubernetes has become the leading platform for container orchestration and cluster management, making it an essential tool for developers and system administrators. In this step-by-step guide, we will show you how to install Kubernetes cluster on Ubuntu 22.04.2 VMware Lab in With the help of bash code, we’ll make the process of installation and configuration easier and faster.
Understanding Kubernetes and VMware Lab Before we dive into the installation process, let’s take a moment to understand what Kubernetes and VMware Lab are. Kubernetes is an open-source container orchestration platform that enables the deployment, scaling, and management of containerized applications. VMware Lab is a virtualization platform that provides a computing environment for creating and managing virtual machines.
Prerequisites To follow this guide, you will need:
- A working VMware Lab environment with three ubuntu 20.04.2 installed vms
- A Ubuntu 22.04.2 virtual machine (Master, Worker1, Worker2)
- VMs=3, Processor=2CPU, Disk=20GB free disk space or more
- Root access to the Ubuntu 22.04.2 virtual machine
- Basic knowledge of Linux commands
- Internet connectivity
Skip Ubuntu 22.04.2 Intstallation Guide
Lab Setup
- VM1=Kubernetes Master Node: 192.168.1.120 – master.ubuntu.biz<hostname>
- VM2=Worker Node-1: 192.168.1.121 – w1.ubuntu.biz<hostname>
- VM3=Worker Node-2: 192.168.1.122 –w2.ubuntu.biz<hostname>
Installing Kubernetes on Ubuntu 22.04.2
- Update and upgrade the Ubuntu 22.04.2 virtual machine
sudo apt update && sudo apt upgrade
Add hostname entries in the host-nodes, set hostname
- Login to master node vm and set hostname using hostnamectl
sudo hostnamectl set-hostname "master.ubuntu.biz" exec bash
- Login to worker1 nodes vm and set hostname using hostnamectl
sudo hostnamectl set-hostname "w1.ubuntu.biz" //1 worker node exec bash
- Login to worker2 nodes vm and set hostname using hostnamectl
sudo hostnamectl set-hostname "w2.ubuntu.biz" //2 worker node exec bash
Add the following entries in /etc/hosts file on each node (master, w1, w2)
sudo nano /etc/hosts
192.168.1.120 master.ubuntu.biz master 192.168.1.121 w1.ubuntu.biz w1 192.168.1.122 w2.ubuntu.biz w2
Install Docker Container on all VMs
sudo apt install docker.io
- Add user in docker group (dtechyworld)
sudo add usermod -aG docker dtechyworld
- Check docker version currently installed
docker ––version
Enable and Start Docker Container
- Set Docker to launch at boot by entering the following:
sudo systemctl enable docker
sudo systemctl start docker
- Confirm Docker Container running status:
sudo systemctl status docker
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2023-03-20 17:04:01 -03; 3h 1min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 7272 (dockerd) Tasks: 23 Memory: 156.3M CGroup: /system.slice/docker.service └─2282 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
- Add user in sudo group to install kubernetes (optional)
sudo add usermod -aG sudo dtechyworld
Install Kubernetes in Ubuntu 22.04.2
- Add the Kubernetes signing key to the Ubuntu 22.04.2 on each virtual machine
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- if curl is not installed or find error install curl
sudo apt install curl
- Add the Kubernetes repository to the Ubuntu 20.04.2 virtual machine
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
- Update the package list and install Kubernetes components
sudo apt update && sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
- All Steps completed now verify kubeadm
kubeadm version
- Repeat for each server node.
Kubernetes Deployment Controller
Before Initialze kube Disable the swap memory on each server one by one (master, w1, w2)
sudo swapoff –a sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
- Initialize Kubernetes cluster with Kubeadm on Master Ubuntu 20.04.2 virtual Machine
sudo kubeadm init --control-plane-endpoint=master.ubuntu.biz
your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root: kubeadm join master.ubuntu.biz:6443 --token fpzyxd.51my1qocwb68t1nd \ --discovery-token-ca-cert-hash sha256:4cf856842339f8d3bb9bf660212ce5dab743560232334f36e3fc3ebc48dfb1af \ --control-plane Then you can join any number of worker nodes by running the following on each as root: kubeadm join master.ubuntu.biz:6443 --token fpzyxd.51my1qocwb68t1nd \ --discovery-token-ca-cert-hash sha256:4cf856842339f8d3bb9bf660212ce5dab743560232334f36e3fc3ebc48dfb1af
- Copy the kubeconfig file to your home directory or run following
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Install the flannel network addon using the following command on master node
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Joining Worker Nodes to the Kubernetes Cluster
- To join worker nodes to the Kubernetes cluster, got w1 worker node paste or type
kubeadm join master.ubuntu.biz:6443 --token fpzyxd.51my1qocwb68t1nd \ --discovery-token-ca-cert-hash sha256:4cf856842339f8d3bb9bf660212ce5dab743560232334f36e3fc3ebc48dfb1af
- Repeat step on w2 worker node
kubeadm join master.ubuntu.biz:6443 --token fpzyxd.51my1qocwb68t1nd \ --discovery-token-ca-cert-hash sha256:4cf856842339f8d3bb9bf660212ce5dab743560232334f36e3fc3ebc48dfb1af
- kubectl commands to view cluster and node status
kubectl cluster-info kubectl get nodes
NAME STATUS ROLES AGE VERSION master.ubuntu.biz Ready control-plane 50M v1.26.3 w1.ubuntu.biz Ready <none> 10M v1.26.3 w2.ubuntu.biz Ready <none> 10M v1.26.3
if it is not ready so please wait
Test Deployment POD
kubectl create deployment nginx-app --image=nginx --replicas=2
- Check status of deployment Pods
kubectl get deployment nginx-app
NAME READY UP-TO-DATE AVAILABLE AGE nginx-app 2/2 2 2 68s
- Expose node port
$ kubectl expose deployment nginx-app --type=NodePort --port=80 service/nginx-app exposed
- check service status
$ kubectl get svc nginx-app $ kubectl describe svc nginx-app
Hope this guide found useful. That’s all for now..