Putting a pod to sleep in kubernetes

3/7/2019

I know how to put a pod to sleep by command:

kubectl -n logging patch sts <sts name> --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/command", "value": ["sleep", "infinity"] }]'

Whats the command to wake up the pod?

-- mac
google-kubernetes-engine
kubernetes
linux

1 Answer

3/7/2019

What you are actually doing is to update the statefulset, changing the command parameter for its pods. The command parameter sets the entrypoint for the container, in other words, the command that is executed when starting the container.

You are setting that command to sleep infinity. Thus to wake up the pod, just update the statefulset and set the command to the original one.

The best solution to do this would be to just scale the statufulset to 0 replicas with:

kubectl -n logging scale sts <sts name> --replicas 0

And scale up to the original replicas number with:

kubectl -n logging scale sts <sts name> --replicas <original number>

This way you don't have any pod running sleep infinity in your cluster, and you will save costs by not having this useless pods wasting resources.

-- Ignacio Millán
Source: StackOverflow