Setup Kubernetes Cluster in 15 minutes | 2021

0.kubernetes overview

In the Previous Blog Post, I have given a brief of What is Kubernetes and the Architecture of Kubernets. If you have not seen then visit Kubernetes Basic . In this blog, I will show you how you can setup Kubernetes Cluster in 15 minutes. we are going to set up master and worker nodes. You can use AWS t2-medium instance for the Master node since the minimum requirement to create a Master Node is 2 CPU & 4 GB RAM. For Worker Node you can go with t2-micro. But in this Blog, I have chosen all the nodes as t2-micro.

Objectives

  • Setup a Master Node and Worker Node. You can view all the node in master node.

Before you begin Setup Instance in  AWS

  1. Login to AWS Account
  2. Launch 3 Instance(Ubuntu – 16.04 ,t2 Medium) : 1-Master , 2-Worker Node
setup kubernetes cluster

Setup Kubernetes Cluster

Configure in Both Master and Worker Node

sudo su
apt-get update

setup kubernetes cluster
apt-get install apt-transport-https
setup kubernetes cluster

This HTTP is needed for intracluster communication(Particularly from Master to Worker Node)

In Ubuntu 16.04 Docker is already available. You just need to install using the below command

apt install docker.io -y
setup kubernetes cluster

To check if docker is installed or not run ‘docker –version’

Screenshot 2021 08 13 at 9.14.49 AM
systemctl start docker

systemctl enable docker
setup kubernetes cluster

Setup Open GPG Key. This is required for intracluster communication. It will be added to the source key on this node i.e. when K8S send signed info to our host, it is going to accept that information because this open GPG key is present in the source key.

Install GPG key

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

Open Kubernetes list and past deb command

viĀ  /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main

After inserting kubernetes-xenial in kubernetes.list update the repository again.

apt-get update

If on apt-get update you get ERROR ( NO_PUBKEY FEEAA12694307EA071  NO_PUBKEY 8B574C5C2D2836F4BE) then import using 

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY>
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FEEAA12694307EA071
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B574C5C2D2836F4BE

and then run apt-get update

setup kubernetes cluster
apt-get install -y kubelet kubeadm kubectl kubernetes-cni

Configure Master Node

kubeadm init

If you get an error then check kubelet status is running or not. If not then

Make sure you are logged in as root and execute the below two commands :

echo '{"exec-opts": ["native.cgroupdriver=systemd"]}' >> /etc/docker/daemon.json
systemctl restart docker
kubeadm reset

When you run kubeadm init then you will given set of command to run for example

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

You will be even given the join command that you need to run on the worker node to join the master node. Please run the join command when you have configured the flannel.

Configure Flannel

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

CONFIGURE WORKER NODES 

COPY LONG CODE PROVIDED MY MASTER IN NODE NOW LIKE CODE GIVEN BELOW

e.g- kubeadm join 172.31.6.165:6443 –token kl9fhu.co2n90v3rxtqllrs –discovery-token-ca-cert-hash sha256:b0f8003d23dbf445e0132a53d7aa1922bdef8d553d9eca06e65c928322b3e7c0

Open 6443 Port so that master node can connect

If you are getting error failed with error: Get “http://localhost:10248/healthz” then run:

echo '{"exec-opts": ["native.cgroupdriver=systemd"]}' >> /etc/docker/daemon.json 
systemctl restart docker

GO TO MASTER AND RUN THIS COMMAND

kubectl get nodes
Screenshot 2021 08 13 at 3.46.06 PM

That’s all in the Blog. Hope you like it. Don’t forget to subscribe to the latest blog.

Install Kubectl: https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

Leave a comment

Your email address will not be published.


*