#Day31 : Launching your First Kubernetes Cluster with Nginx running

#Day31 : Launching your First Kubernetes Cluster with Nginx running

How Kubernetes makes deployment easier

With Kubernetes, organizations can achieve increased efficiency and agility in their development and deployment processes, resulting in faster time to market and reduced operational costs. Kubernetes also provides a high degree of scalability, allowing organizations to scale their applications as their business grows and evolves easily.

Setting up Master and Node in Kubernetes

Pre-requisites

For the master node, if you are using an AWS instance, you will require a t2.medium instance as you will need two CPUs to run kubeadm.

For worker node, it is ok if we use t2.micro instance.

Setup

Launch both instances or ssh into the instances, whatever is convenient.

Now Install docker on both Master and node.

sudo apt install docker.io -y

sudo systemctl start docker
sudo systemctl enable docker

Also install kubeadm on both master and node.

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Update the system

sudo apt update -y

Install Kubeadm,Kubectl and Kubelet in both Master and Node.

sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y

Now, on both master and node, gain in superuser access

sudo su

Now in master, run kubeadm

kubeadm init

Now, run in master

export KUBECONFIG=/etc/kubernetes/admin.conf

To finish Master setup,

kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml

kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml

Call kubeadm to create token for node connection:

kubeadm token create --print-join-command

It will give us a token. Copy this token and take it to worker node and paste it there.

Your node will be connected to the master.

To check, go to master and type

kubectl get nodes

Running a pod

Kubernetes Pod Logo

Running a Pod on Kubernetes is pretty easy

kubectl run nginx --image=nginx

By default, the kubectl run command creates a deployment and a replica set along with the pod. If you only want to create a pod without creating a deployment or replica set, you can use the --restart=Never flag:

kubectl run nginx --image=nginx --restart=Never

Now, go to worker node and check whether pod is up -

docker ps

To check pods, in master

kubectl get pods

To delete pod

kubectl delete pod nginx

We can also create a new pod from an image from docker hub using a YAML file

To run it, on master node:

kubectl apply -f pod.yml