Kubernetes Cluster In Simple Steps

Search for a command to run...

No comments yet. Be the first to comment.
API (Application Programming Interface) security is critical for protecting sensitive data and maintaining the integrity of systems and applications. APIs are used to connect different systems and applications, and as a result, they can provide a gat...

Well after months of deep slumber, away from social media networks, I had to return to Pune and adapt to hybrid working. I was browsing through meetup.com and was intrigued by one event from AWS user group Pune. It is AWS Reinvent 2022 -Recap on 21st...

Episode 2

Simplify Access Control and Enhance Transparency Over Your ML Projects

Episode 1

Does that word cluster amaze you? If you are trying to get an Kubernetes cluster running by yourself. Then you are at the right place. The article covers simple to do steps to understand kubernetes by setting up a simple cluster with a master and 2 worker nodes on Google Cloud Platform. The use of GCP is a personal choice but the same procedure can be followed in other vendors as the steps are to be followed on Ubuntu Virtual Machines on the cloud platform.
Kubernetes is a widely used container orchestration tool. It has its own pros and cons but having a solid understanding of how it works is going to help you a lot to stay with technology trends in the cloud native space. Spend some time getting yourself familiarized and you would not regret it.
Prerequisites:
Once we have the 3 Machines set up, the next step is to install the requisite packages and software on the Machines so they are ready to function as a Kubernetes Cluster.
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
> deb https://apt.kubernetes.io/ kubernetes-xenial main
> EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
(TO BE RUN ONLY ON THE WORKER NODES):
apt-mark hold kubelet kubeadm kubectl
As a root user execute the below commands on master and worker nodes
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
docker -v
rm /etc/containerd/config.toml
systemctl restart containerd
As a root user on the master node, execute the below commands
kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr=192.168.0.0/16
Once we have run the above command, it produces output that contains the information about the kubernetes cluster and the information has to be kept safe and secure.



mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export kubever=$(kubectl version | base64 | tr -d '\n')
(Kube Proxy Addon Installation):
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
kubectl get nodes
When we run the kubectl get nodes on the Master Machine, the output just displays the master machine.
To add the worker nodes on to the kubernetes cluster, run the output from the kubeadm init command on the worker nodes as shown below

Now when we run the “kubectl get nodes” on the master node, we will be able to see the master and workernode1 listed as nodes to the kubernetes cluster. The same has to be repeated on worker node 2 to join to the cluster.
So why would should we try setting this up manually when there are lot of managed kubernetes instance provided by cloud providers. Setting up the kubernetes cluster help us understand the various components that are installed while we run the kubeadm init command and how a node is joined as worker to the master. This helps in creating a Mind Map that retains in the memory for a longer time than while reading.
If you are someone who would like to fork a github repo and try out the commands, please refer to
If video format makes it impressive, please refer to
https://www.youtube.com/watch?v=md2BtnJYtt8&list=PLh_VNk4-EHTMhIR-NIgI4tCEHdO9U-A8F&index=3
Happy Learning!!!
Please feel free to post any queries/clarifications.