Kubernetes – Prevent Empty Replicasets From Deployments

Kubernetes deployments are funny. For every kubectl rollout restart deployment (or it’s API equivalent), there is a new -empty- statefulset…

If you want to take a look, run the following:

kubectl get replicaset -o jsonpath='{ .items[?(@.spec.replicas==0)].metadata.name }'

Quite allot huh?

Clean them up with:

kubectl delete replicaset $(kubectl get replicaset -o jsonpath='{ .items[?(@.spec.replicas==0)].metadata.name }')

To prevent a new empty replicaset for every new deployment, add:

revisionHistoryLimit: 0

To your deployment, this will prevent each new rollout creating up to the default ten (!!!) new replicasets.

Good luck 👾

Leave a Reply

Your email address will not be published. Required fields are marked *