Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suspending a container in a kubernetes pod

Tags:

kubernetes

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?

like image 977
WaxOnWaxOff Avatar asked Apr 25 '17 17:04

WaxOnWaxOff


People also ask

How do you suspend a pod in Kubernetes?

Kubernetes does not allow you to stop or pause a pod's present state and resume it later. No. It is not feasible to pause a pod and restart it at a later time. Pods are encapsulated in Kubernetes utilizing a service.

How do I suspend a job on Kubernetes?

With the recent Kubernetes 1.21 release, you will be able to suspend a Job by updating its spec. The feature is currently in alpha and requires you to enable the SuspendJob feature gate on the API server and the controller manager in order to use it.


2 Answers

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>
like image 121
LukeCC Avatar answered Oct 06 '22 14:10

LukeCC


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.

like image 25
surajd Avatar answered Oct 06 '22 14:10

surajd