# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
