In order to leverage Kubernetes platform for deploying Containerized Applications, we need to set up a Kubernetes cluster. In my Home Lab, i have used 2 Ubuntu 18.0.4.03 Virtual Machines to create a Kubernetes cluster. Ubuntu machines should have Internet connectivity, name resolution should work between both the machines and machines should be patched & updated.
Configuring a Kubernetes Cluster on Ubuntu:
Pre-requisites:
1. 2 X Ubuntu 18.04.3 VMs
2. Each VM should have minimum of 2 vCPUs and 2 GB RAM
Configuration Steps:
1. Install Docker on both the nodes:
sudo apt install docker.io
Run the below command to check the verion of Docker:
docker –version
2. Enable Docker on both the nodes:
sudo systemctl enable docker
Run the following command to install curl on both the VMs:
sudo apt install curl
4. Add the Kubernetes signing key on both the nodes:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
5. Add Xenial Kubernetes Repository on both the nodes:
sudo apt-add-repository “deb http://apt.kubernetes.io/ kubernetes-xenial main”
6. Install Kubeadm:
sudo apt install kubeadm
kubeadm version
7. Deploy Kubernetes Cluster:
Disable swap memory (if running) on both the nodes:
sudo swapoff -a
8. Give Unique hostnames to each node:
sudo hostnamectl set-hostname kube-master
hostnamectl set-hostname kube-node1
9. Initialize Kubernetes on the master node:
sudo kubeadm init –pod-network-cidr=10.244.0.0/16
Note down the output of the above command in a Notepad, you’ll require the discovery token to join the Worker Node to the cluster.
10. 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
You can check the status of the master node by running the following command:
kubectl get nodes
11. Deploy a Pod Network through the master node:
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Use the following command in order to view the status of the network:
kubectl get pods –all-namespaces
Use the following command to check the status of the Master Node:
sudo kubectl get nodes
12. Create a Service Account to Access the Kuberntes UI Dashboard:
kubectl create serviceaccount dashboard -n default
Assign Cluster-Admin Privileges to the Service Account:
kubectl create clusterrolebinding dashboard-admin -n default –clusterrole=cluster-admin –serviceaccount=default:dashboard
Generate a Bearer Token for the Service Account to Access the Dashboard UI:
kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath=”{.secrets[0].name}”) -o jsonpath=”{.data.token}” | base64 –decode
Token:
eyJhbGciOiJSUzI1NiIsImtpZCI6Ik95R3ZaUXBCeWVYS01IQ3JfNms3eWJ0MlZrQzI3WHRH
NFhKUEtsc3VieEkifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJu
ZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRl
cy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRhc2hib2FyZC10b2tlbi14Znp3
biIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbW
UiOiJkYXNoYm9hcmQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtY
WNjb3VudC51aWQiOiIxMzk4ZWU3OS1hZjNmLTQ0YzctOTkxOC0zZTMxNWRkNWRlM2Ei
LCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDpkYXNoYm9hcmQifQ.LW
keqAnIsylBvH9fRL_e5Uabcdefashajshkjahsjkahsjabxabsnbavhgqw872y2hjbnasbnmasba
12. Deploying the Dashboard UI:
For those of you who didn’t knew, Kubernetes has a GUI based Dashboard which can be used for almost every admin task once the cluster has been set up. Use the below steps to deploy the Dashboard UI:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
You can now access the Dashboard using the kubectl command-line tool by running the following command:
Kubectl proxy
Kubectl will make Dashboard available at:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Access the above dashboard by entering the above URL in a Web Browser and login using the Bearer Token:

14. Add the slave node to the network in order to form a cluster:
kubeadm join Kube-Master_FQDN:6443 –token kjq37t.2nqh0m4y31ytnzt4 \
–discovery-token-ca-cert-hash sha256:8da665906a2a1ff54ee50efa6c1d0088fb27399b2e649e4ca8cfe8ee115a9728
Use the following command to check the status of all the Cluster Nodes:
sudo kubectl get nodes
If you have followed all the above steps the Output should be something like this:

Pro-Tip:
Some people like to use Pycharm for writing YAML files for Kuberetes but i like to use Visual Studio Code for all my Command Line stuff. You can install an extension for Remote-SSH in Visual Studio Code and connect to your Kubernetes Cluster using Visual Stutio Code.

Enjoy your newly built Kubernetes Cluster. 🙂

































