---
title: "Master How to Restart Pods in Kubernetes [Step by Step]"
description: "Need to restart pods in Kubernetes? Learn how to keep your pods running in this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/restart-pod-kubernetes/"
---

# Master How to Restart Pods in Kubernetes [Step by Step]

> Need to restart pods in Kubernetes? Learn how to keep your pods running in this step-by-step tutorial!

Source: https://adamtheautomator.com/restart-pod-kubernetes/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Master How to Restart Pods in Kubernetes \[Step by Step\]](https://adamtheautomator.com/wp-content/uploads/2021/10/How-to-Restart-Pods-in-Kubernetes-Step-by-Step.jpg)

# Master How to Restart Pods in Kubernetes \[Step by Step\]

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)10 November 20214 min. read

Categories: [DevOps](/category/devops/)

Tags:[Kubernetes](/tag/kubernetes/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Restart Pods in Kubernetes by Changing the Number of Replicas](#restart-pods-in-kubernetes-by-changing-the-number-of-replicas)
*   [Restart Pods in Kubernetes with the rollout restart Command](#restart-pods-in-kubernetes-with-the-rollout-restart-command)
*   [Restart Pods in Kubernetes by Updating the Environment Variable](#restart-pods-in-kubernetes-by-updating-the-environment-variable)
*   [Conclusion](#conclusion)

If you’re managing multiple pods within [Kubernetes](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/), and you noticed the status of [Kubernetes pods](https://kubernetes.io/docs/concepts/workloads/pods/) is pending or in the inactive state, what would you do? The quickest way to get the pods running again is to restart pods in Kubernetes.

In this tutorial, you will learn multiple ways of rebooting pods in the Kubernetes cluster step by step. So sit back, enjoy, and learn how to keep your pods running.

Let’s get started!

## Prerequisites

This tutorial houses step-by-step demonstrations. To follow along, be sure you have the following:

*   [Ubuntu](https://adamtheautomator.com/installing-kubernetes-on-ubuntu/) 14.04.4 LTS machine or greater with Docker installed – This tutorial uses [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) with [Docker v19.03.8](https://docs.docker.com/engine/install/ubuntu/).
*   A Kubernetes cluster

Related:[How to Install Kubernetes on an Ubuntu machine](https://adamtheautomator.com/installing-kubernetes-on-ubuntu/)

*   The [kubectl command-line interface](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) is installed and configured to your cluster.

## Restart Pods in Kubernetes by Changing the Number of Replicas

There are many ways to restart pods in kubernetes with kubectl commands, but for a start, first, restart pods by changing the number of replicas in the [deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/).

In this strategy, you scale the number of deployment replicas to zero that stops all the pods and further terminates them. Pods are later scaled back up to the desired state to initialize the new pods scheduled in their place.

> _If you set the number of replicas to zero, expect a downtime of your application as zero replicas stop all the pods, and no application is running at that moment._

1\. Open your terminal and run the commands below to create a folder in your home directory, and change the working directory to that folder.

In this tutorial, the folder is called _~/nginx-deploy,_ but you can name it differently as you prefer. This folder stores your Kubernetes deployment configuration files.

```bash
mkdir ~/nginx-deploy
cd ~/nginx-deploy
```

2\. Next, open your favorite code editor, and copy/paste the configuration below. Save the configuration with your preferred name. But for this example, the configuration is saved as _nginx.yaml_ inside the _~/nginx-deploy_ directory.

The below _nginx.yaml_ file contains the code that the deployment requires, which are as follows:

*   **Name:** `nginx-deployment` – The deployment name.
*   **Labels**: `app:nginx` – Used for tagging.
*   **Replicas**: `2` – Allows you to define the number of pods you need for deployment
*   **“Spec” Section** – This allows you to specify the container details, such as the image (`nginx`) container’s name (`nginx-pod`).

```yaml
# Defining the Kubernetes API version
apiVersion: apps/v1
# Defining the type of the object to create
kind: Deployment
# Metadata helps uniquely identify the object, 
# including a name string, UID, and optional namespace.
Metadata:
  name: nginx-deployment
# Labels are key/value pairs that are attached to objects, such as pods. 
# Labels are intended to be used to specify identifying attributes 
# of objects that are meaningful and relevant to users.
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-pod
        image: nginx
```

3\. Run the [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) command below to pick the `nginx.yaml` file and create the deployment, as shown below. `kubectl apply -f nginx.yaml`

```bash
kubectl apply -f nginx.yaml
```

![Creating the deployment using the nginx.yaml file and kubectl apply command](https://adamtheautomator.com/wp-content/uploads/2021/10/image-330.png)

Creating the deployment using the nginx.yaml file and kubectl `apply` command

4\. Now, execute the [`kubectl get`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#get) command below to verify the pods running in the cluster, while the `-o wide` syntax provides a detailed view of all the pods.

```powershell
kubectl get pods -o wide
```

![Verifying the pods in the Kubernetes cluster](https://adamtheautomator.com/wp-content/uploads/2021/10/image-331.png)

Verifying the pods in the Kubernetes cluster

5\. Run the [`kubectl scale`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#scale) command below to terminate all the pods one by one as you defined 0 replicas (`--replicas=0`).

```bash
kubectl scale deployment nginx-deployment --replicas=0
```

![Scaling the deployment to Zero Pods](https://adamtheautomator.com/wp-content/uploads/2021/10/image-332.png)

Scaling the deployment to Zero Pods

6\. Run the `kubectl get pods` command to verify the numbers of pods.

```powershell
kubectl get pods
```

Notice below that all the pods are currently terminating. Keep running the `kubectl get pods` command until you get the “**No resources are found in default namespace”** message.

![Verifying the pods in the Kubernetes cluster](https://adamtheautomator.com/wp-content/uploads/2021/10/image-333.png)

Verifying the pods in the Kubernetes cluster

7\. Now run the `kubectl scale` command as you did in step five. But this time, the command will initialize two pods one by one as you defined two replicas (`--replicas=2`).

```bash
kubectl scale deployment nginx-deployment --replicas=2
```

![Scaling the deployment to Two Pods](https://adamtheautomator.com/wp-content/uploads/2021/10/image-334.png)

Scaling the deployment to Two Pods

8\. Finally, run the command below to verify the number of pods running. `kubectl get pods`

```powershell
kubectl get pods
```

You will notice below that each pod runs and are back in business after restarting.

![Verifying the pods in the Kubernetes cluster are running](https://adamtheautomator.com/wp-content/uploads/2021/10/image-335.png)

Verifying the pods in the Kubernetes cluster are running

## Restart Pods in Kubernetes with the `rollout restart` Command

You’ve previously configured the number of replicas to zero to restart pods, but doing so causes an outage and downtime in the application. So how to avoid an outage and downtime? By running the [`rollout restart`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-restart-em-) command.

Run the `rollout restart` command below to restart the pods one by one without impacting the deployment (`deployment nginx-deployment`).

```powershell
kubectl rollout restart deployment nginx-deployment
```

![Running the rollout restart command in the Kubernetes cluster](https://adamtheautomator.com/wp-content/uploads/2021/10/image-336.png)

Running the rollout restart command in the Kubernetes cluster

Now run the `kubectl` command below to view the pods running (`get pods`).

```powershell
kubectl get pods
```

Notice below that two of the old pods shows **Terminating** status, then two other shows up with **Running** status within a few seconds, which is quite fast. Why? Because there’s no downtime when running the `rollout restart` command.

![Verifying the Pods in the Kubernetes cluster](https://adamtheautomator.com/wp-content/uploads/2021/10/image-337.png)

Verifying the Pods in the Kubernetes cluster

## Restart Pods in Kubernetes by Updating the Environment Variable

By now, you have learned two ways of restarting the pods, by changing the replicas and by rolling restart. In both approaches, you explicitly restarted the pods. But in the final approach, once you update the pod’s [environment variable](https://kubebyexample.com/en/concept/environment-variables), the pods automatically restart by themselves.

1\. Run the [`kubectl set env`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-env-em-) command below to update the deployment by setting the `DATE` environment variable in the pod with a null value (`=$()`). As soon as you update the deployment, the pods will restart.

```bash
kubectl set env deployment nginx-deployment DATE=$()
```

![ Updating Deployment to Restart Pods in Kubernetes Automatically ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-338.png)

Updating Deployment to Restart Pods in Kubernetes Automatically

2\. Now execute the below command to verify the pods that are running.

```bash
kubectl get pods
```

Below, you’ll notice that the old pods show **Terminating** status, while the new pods show **Running** status after updating the deployment.

![Listing All Pods](https://adamtheautomator.com/wp-content/uploads/2021/10/image-339.png)

Listing All Pods

3\. Finally, run the [`kubectl describe`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe) command to check if you’ve successfully set the DATE environment variable to null.

```bash
kubectl describe
```

Notice below that the **DATE** variable is empty (null).

![Verifying if the DATE variable is set to null](https://adamtheautomator.com/wp-content/uploads/2021/10/image-340.png)

Verifying if the DATE variable is set to null

## Conclusion

In this tutorial, you learned different ways of restarting the Kubernetes pods in the Kubernetes cluster, which can help quickly solve most of your pod-related issues.

Now, instead of manually restarting the pods, why not automate the restart process each time a pod stops working?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Frestart-pod-kubernetes%2F&text=Master%20How%20to%20Restart%20Pods%20in%20Kubernetes%20%5BStep%20by%20Step%5D)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Frestart-pod-kubernetes%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Frestart-pod-kubernetes%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/07/featured_image-3.png)

### [Build Your First Internal Developer Platform](/build-first-internal-developer-platform/)

Build your first Internal Developer Platform with Backstage, a software catalog, software templates, CI/CD handoffs, and Kubernetes deployment manifests.

![](https://adamtheautomator.com/wp-content/uploads/2026/06/featured_image-9.png)

### [DevOps to Platform Engineer: 2026 Transition Roadmap](/devops-platform-engineer-2026-transition-roadmap/)

Learn how to move from DevOps to platform engineering in 2026 with a practical roadmap covering transferable skills, internal developer platforms, Backstage, Crossplane, and portfolio projects.

![](https://adamtheautomator.com/wp-content/uploads/2024/02/kubernetes-blue-green.jpg)

### [Learning the Kubernetes Blue Green Deployment Strategy](/kubernetes-blue-green/)

Dive into Kubernetes blue-green deployments for smooth updates. Enhance your release process with this smart Kubernetes strategy!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
