Restarting resources such as deployments in Kubernetes is a fairly common task, and starting with Kubernetes v1.15 there's an easy command for it.
Kubernetes v1.15 was released on Jun 19, 2019. See "Restarting Deployments in Kubernetes Before v1.15" for the older method.
Jul 10, 2020 · 3 min read
Restarting resources such as deployments in Kubernetes is a fairly common task, but before v1.15 it wasn't very straight-forward.
There's a bunch of reasons why you'd want to restart a resource in Kubernetes:
- The code running in a pod is in a "hung" state and liveness probes don't exist or aren't ejecting it.
- A config map has changed and a deployment restart is needed for it to be applied.
- You're doing some low-grade chaos engineering and want to check for crash/restart tolerance.
- And more!
Thankfully there's an easy command to restart different types of resources:
kubectl rollout restart <resource>
According to the changelog, here's the different resources that are supported right now:
- Daemon sets
- Stateful sets
Here's a quick example of how to restart a deployment named
kubectl rollout restart deployment/api deployment.extensions/api restarted