How to Resart Pod In kubernetes?
Last Updated :
30 Apr, 2024
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:
- Autoscaling: Kubernetes provides both a horizontal pod autoscaler and a vertical pod autoscaler to scale up or down based on the amount of traffic the application receives.
- Autohealing: Kubernetes automatically starts a new pod if there is any pod failure or deletion.
- High Availability: Kubernetes provides a replica set controller, which helps in maintaining the desired number of pods running on a cluster.
- Deployment process: Kubernetes helps automate the deployment process by rolling out new updates with zero downtime.
- Roll Back: Kubernetes allows you to roll back with zero downtime to the previous version of the application if any issues occur in the current version of the application.
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
.jpg)
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.
Similar Reads
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response
In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network
Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java
Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
3-Phase Inverter
An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker?
A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
What Is Cloud Computing ? Types, Architecture, Examples and Benefits
Nowadays, Cloud computing is adopted by every company, whether it is an MNC or a startup many are still migrating towards it because of the cost-cutting, lesser maintenance, and the increased capacity of the data with the help of servers maintained by the cloud providers. Cloud Computing means stori
15 min read