How to rollout without killing processes in K8s?

Viewed 77

I'm using:

kubectl rollout restart deployment my_cool_workers

This terminates the workers and start new ones. However I want to rollout in a way where if something is running on a specific worker I want to let the task finish - I don't want to kill the tasks (so the worker should finish the tasks but not accepting new)

Meaning - rollout new workers -> old workers no longer accept traffic -> when old worker is no longer running anything terminate it.

How can this be done?

1 Answers

If a Pod gets killed, manually via kubectl or by any k8s controller like during a deployment, it will instantly change from Running into Terminating state. At the same time, the SIGTERM signal will be sent to all containers inside that Pod.

Starting from Kubernetes 1.19 you can debug running pods using Ephemeral Containers and kubectl debug command.

While in Terminating state, containers of a Pod are not restarted if they end. Whenever a container inside a Pod stops while in Running state, the container is restarted. This is done because a Pod should always be running unless an error occurred.

For more information refer to this document.

Related