Open In App

How to Resart Pod In kubernetes?

Kubernetes is an open-source container orchestration tool that helps in scaling, deploying, and managing containerized applications. In Kubernetes, the pods are the smallest deployable unit. In this guide, I will first discuss what Kubernetes is. Then I will discuss what is pods in Kubernetes. After this, I will walk you through the different steps to restart a pod in Kubernetes.

What is Kubernetes?

Kubernetes is a container orchestration tool that helps in scaling, deploying, and managing containerized applications. Kubernetes follows a master-slave architecture. Here, the master node, also called the control plane, manages all the cluster operations. On the other hand, worker nodes help in deploying and executing containers. The master node consists of 4 main components, the API server, which helps in interacting with the Kubernetes cluster; the scheduler, which helps in scheduling the pods to run on which node; ETCD, which stores all the Kubernetes cluster data; and controls managers, which help in managing different controllers like deployments, replica sets, and many more. Apart from this, in the worker node, there is kubelet, which helps in managing the pod lifecycle on a node; container runtime, which helps in running the containers; and kube-proxy, which helps in managing the network rules in the pods.



Kubernetes provides a variety of features, such as:

What is Pod in Kubernetes?

Pod is a smallest deployable unit in the Kubernetes . Pods encapsulate the application container , storage , network and other configurations . Each pod has its own IP . These pods can also interact with each other with these IP addresses . Kubernetes manages the lifecycle of the pods . Based on the traffic an application receives these pods can be scaled up or scaled down . Controllers like Deployment controllers helps in scaling , restarting and recovering pods form failures . In summary we can say pods are the simple deployable units which provides a flexible and scalable framework for orchestrating and deploying the containerized application in Kubernetes .



Pre-requisites

Before moving to next section make sure you have installed Minikube on your system . If not installed follow this Geeks For Geeks article Kubernetes Minikube to install Minikube on your system .

Steps to Restart Pod In Kubernetes

Method 1: Restart By Deleting Pod

Step 1: Create a cluster using minikube.

minikube start

Step 2: Create a deployment.

kubectl create deployment nginx-deployment --image=nginx --replicas=1

Step 3: See pod the status using the command below.

kubectl get pods

Step 4: Delete a pod from the cluster.

kubectl delete pod <pod-name>

Step 5: Again see the pod status. You will observe even the pod is deleted, another pod will automatically run.

kubectl get pods

Method 2: Restart Pod By Using Rollout Restart

You can also restart a pod by using kubectl rollout restart . Follow the step below to restart a pod:

Step 1: Create a deployment.

kubectl create deployment nginx-deployment --image=nginx --replicas=1

Step 2: Restart the pod using kubectl restart rollout. Here the running pod will be terminated and a new pod will immediately starts running.

kubectl rollout restart deployment nginx-deployment

Method 3: Restart Pod By using Deployment Scale Methods

You can also scale your deployment to 0, to delete a pod and again scale it desired number of pods. Follow the steps below to restart a pod.

Step 1: Create a deployment.

kubectl create deployment nginx-deployment --image=nginx --replicas=1

Step 2: Scale the deployment to 0.

kubectl scale deployment/nginx-deployment --replicas=0

Step 3: Again scale the deployment to desired number of pods.

kubectl scale deployment/nginx-deployment --replicas=1

Method 4: Restart Pod By Updating Image

You can also set the image to new latest image to restart the pod.

Step 1: Create a deployment.

kubectl create deployment nginx-deployment --image=nginx --replicas=1

Step 2: Update the image to restart the pod.

kubectl set image deployment/nginx-deployment nginx=nginx:latest

Method 5: Restart Pod By Replacing Specified Pod

You can also replace the pod specified to restart the pod. Follow the steps below.

Step 1: Create a deployment.

kubectl create deployment nginx-deployment --image=nginx --replicas=1

Step 2: Get the pod name and replace it.

kubectl get pod nginx-deployment-6c878976f6-klcw7 -o yaml | kubectl replace -f -

Conclusion

Here is this article you have first learned what is Kubernetes. Then you have learned what is pods in Kubernetes. After this you have create deployment on Kubernetes cluster. Then to restart a pod, you have deleted a pod from the Kubernetes cluster. Finally you have observed a new pod starts running automatically after deletion of the pod.

How to Restart Pod In Kubernetes? – FAQs

How to delete a Pod from Kubernetes cluster?

To delete a Pod in Kubernetes cluster you have to use the command “kubectl delete pod <pod-name>“.

What are the different problems you face when there is frequent pod restart?

Frequent pod restart may impact the application performance and may cause temporary downtime.

Is there any command which helps in restarting the pod directly?

No there isn’t a direct command which will directly restart a pod.

How to check pod logs?

To check pod logs you have to use “kubectl logs <pod-name>“.

What are the roles of deployment controller?

Deployment controller automatically manage the pod lifecycle such as restarts, scaling and recovery from the pod failures.


Article Tags :