> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/operations/deployment/deployment-guide/redistribute-pods-across-nodes-by-restarting-deployment-statefulsets.md).

# Restart Deployment or StatefulSets to Redistribute Pods across Nodes

The document explains how to redistribute pods across nodes by restarting deployment or StatefulSets.

While using Kubernetes, it may be necessary to redistribute pods across nodes to balance the load, apply updates, or manage resource usage. One way to achieve this is to restart the deployment or statefulsets, which will terminate the current pods and create new ones, causing them to be rescheduled across the available nodes.

The steps to accomplish this task are given below.

### **Prerequisites**

* You need `kubectl` installed and configured to access your Kubernetes cluster.
* Ensure you have the necessary permissions to manage deployments and statefulsets in your cluster.

### Procedure

1. Determine the name of the deployment or statefulset you want to restart. You can list them using command below.

   ```
   kubectl get deployments -n <namespace>
   kubectl get statefulsets -n <namespace>
   ```
2. To restart a deployment, you can use the `kubectl rollout restart` command. This will update the deployment's pods to the latest state and cause them to be rescheduled.

   ```sh
   kubectl rollout restart deployment <deployment-name> -n <namespace>
   ```
3. Restarting a statefulset is slightly different. You need to update the annotation to trigger a restart.

   ```sh
   kubectl patch statefulset <statefulset-name> -p '{"spec":{"template":{"metadata":{"annotations":{"date":"`date +'%s'`"}}}}}' -n <namespace>
   ```
4. After restarting the deployment or statefulset, you should verify that the pods are being redistributed and running correctly.

   ```bash
   kubectl get pods -n <namespace>
   ```
5. Check the status of the pods and ensure they are running on different nodes as expected.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/operations/deployment/deployment-guide/redistribute-pods-across-nodes-by-restarting-deployment-statefulsets.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
