Day 31 Task: Launching your First Kubernetes Cluster with Nginx running

Day 31 Task: Launching your First Kubernetes Cluster with Nginx running

Kubernetes:

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It simplifies the management of containers by providing a unified API to manage them across different cloud providers and operating systems. In this blog post, we will guide you through the process of setting up a master and node in Kubernetes and creating your first pod on Kubernetes through kubeadm.

Setting up a master and node in Kubernetes:

To set up a master and node in Kubernetes, follow these steps:

Step-1 Launch Two Instance One is Mater and other as Node.

Step-2 Install Docker on both Master and Node.

sudo apt install docker.io -y

sudo systemctl start docker
sudo systemctl enable docker

Step-3 Install Kebeadm 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

Step-4 Again update system.

sudo apt update -y

Step-5 Install Kubeadm,Kubectl and Kebelet in both Master and Node.

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

Step-5 Connect Master with Node:

Initialized Kubeadm:

Run following command only on Master:

sudo su
kubeadm init

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

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

As I am Root user I will run : (In master only)

export KUBECONFIG=/etc/kubernetes/admin.conf

Step-6: Finish the Master Setup using the following Command:

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

Step-7- Call kubeadm to create token for node connection:

kubeadm token create --print-join-command

Step-8 Reset the checks so that i can join fresh server:

kubeadm reset pre-flight checks

Step-9 Provide the token to Node Server:

Step-10 :

Verify by running the command in Master:

See the source image

kubectl gets nodes

Create first Nginx Pod :

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

docker ps

To check the Pods:

To delete that Pod:

kubectl delete pod nginx

We can also Create POD through YML File.

Now Run it :

 kubectl apply -f <name.yml>