---
runspace: 1
title: Restart a deployment that stopped answering
collection: Templates
variables:
    - name: namespace
      default: production
    - name: deployment
      default: api
---

# Restart a deployment that stopped answering

> A template with a worked example. The shape is the point: facts first, then
> the smallest reversible change, then a check that the original signal is
> gone. Replace the commands with your own; keep the shape.
>
> Imports into Runspace as a runbook. Every fenced command becomes a step a
> person approves before it runs. Fence attributes mark which steps change
> things.

## 1. Establish the facts

Write down what was observed before touching anything: the alert or report,
when it started, which users or services are affected, and the links.

Confirm the deployment and its rollout state. Nothing here changes anything.

```sh {intent="diagnostic"}
kubectl -n {{namespace}} rollout status deploy/{{deployment}} --timeout=10s
```

```sh {intent="diagnostic"}
kubectl -n {{namespace}} get pods -l app={{deployment}} -o wide
```

Look at the most recent events for the deployment's pods. Crash loops, failed
probes, image pull errors and evictions show up here first.

```sh {intent="diagnostic"}
kubectl -n {{namespace}} get events --field-selector involvedObject.kind=Pod --sort-by=.lastTimestamp | tail -n 30
```

Check: the facts name one deployment in one namespace, and the pods listed
are the ones you expect. If the symptom is somewhere else, stop here.

## 2. Test a hypothesis

State the hypothesis in one line and the evidence that would disprove it.
For a deployment that stopped answering, the usual one is a hung process or
exhausted connections inside otherwise healthy pods.

Read the current logs of one pod before restarting. A restart destroys this
evidence.

```sh {intent="diagnostic"}
kubectl -n {{namespace}} logs deploy/{{deployment}} --tail=200 --timestamps
```

## 3. Recover

The smallest reversible change is a rolling restart: new pods come up before
old ones go, and the deployment's own rollback history is untouched.

```sh {intent="change" timeout=600}
kubectl -n {{namespace}} rollout restart deploy/{{deployment}}
```

```sh {intent="diagnostic" timeout=600}
kubectl -n {{namespace}} rollout status deploy/{{deployment}} --timeout=10m
```

Roll back only if the restart made things worse, not merely if it did not
help:

```sh {intent="change" timeout=600}
kubectl -n {{namespace}} rollout undo deploy/{{deployment}}
```

## 4. Verify against the original signal

A completed restart is not a recovery. Check the thing that was wrong, not
the thing you changed: the alert clears, the endpoint answers, the error rate
drops. Record what you checked and when.

```sh {intent="diagnostic"}
kubectl -n {{namespace}} get pods -l app={{deployment}}
```

## 5. Leave it better

- What was the cause? If you do not know, the incident is not over.
- What would have caught it earlier?
- Which step of this runbook was wrong, vague, or missing?
- Is there a fix to the system that would remove this runbook?
