Suspending a container in a kubernetes pod

4/25/2017

I would like to suspend the main process in a docker container running in a kubernetes pod. I have attempted to do this by running

kubectl exec <pod-name> -c <container-name> kill -STOP 1

but the signal will not stop the container. Investigating other approaches, it looks like docker stop --signal=SIGSTOP or docker pause might work. However, as far as I know, kubectl exec always runs in the context of a container, and these commands would need to be run in the pod outside the context of the container. Does kubectl's interface allow for anything like this? Might I achieve this behavior through a call to the underlying kubernetes API?

-- WaxOnWaxOff
kubernetes

2 Answers

12/17/2018

You could set the replicaset to 0 which would set the number of working deployments to 0. This isn't quite a Pause but it does Stop the deployment until you set the number of deployments to >0.

kubectl scale --replicas=0 deployment/<pod name> --namespace=<namespace>
-- LukeCC
Source: StackOverflow

4/26/2017

So kubernetes does not support suspending pods because it's a VM kinda behavior, and since starting a new one is cheaper it just schedules a new pod in case of failure. In effect your pods should be stateless. And any application that needs to store state, should have a persistent volume mounted inside the pod.

The simple mechanics(and general behavior) of Kubernetes is if the process inside the contaiener fails kuberentes will restart it by creating a new pod.

If you also comment what you are trying to achieve as an end goal I think I can help you better.

-- surajd
Source: StackOverflow