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.
- Virtual Machine 1 (named as MASTER) with 2cpu and 4 GB RAM Ubuntu Machine
- Virtual Machine 2 (named as WorkerNode1) with 2cpu and 4GB RAM Ubuntu Machine
- Virtual Machine 3 (named as WorkerNode2) with 2cpu and 4GB RAM Ubuntu Machine
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.
COMMANDS TO BE RUN ON ALL 3 MACHINES UNLESS STATED OTEHRWISE
INSTALL DOCKER ENGINE ON ALL NODES:
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 install -y kubelet kubeadm kubectl
(TO BE RUN ONLY ON THE WORKER NODES):
apt-mark hold kubelet kubeadm kubectl
INSTALL DOCKER PACKAGES ON ALL THE NODES
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
systemctl restart containerd
INITIALIZATION OF KUBE MASTER: TO BE RUN ONLY ON THE MASTER NODE
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
Please feel free to post any queries/clarifications.
Community and Social Footprints :
Did you find this article valuable?
Support Cloudnloud Tech Community by becoming a sponsor. Any amount is appreciated!