Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stop/pause a pod in kubernetes

I have a MySQL pod running in my cluster.
I need to temporarily pause the pod from working without deleting it, something similar to docker where the docker stop container-id cmd will stop the container not delete the container.
Are there any commands available in kubernetes to pause/stop a pod?

like image 394
AATHITH RAJENDRAN Avatar asked Feb 22 '19 06:02

AATHITH RAJENDRAN


People also ask

How do you pause or stop 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.

What is pause in Kubernetes?

Every Kubernetes Pod includes an empty pause container, which bootstraps the Pod to establish all of the cgroups, reservations, and namespaces before its individual containers are created. The pause container image is always present, so the pod resource allocation happens instantaneously as containers are created.


1 Answers

So, like others have pointed out, Kubernetes doesn't support stop/pause of current state of pod and resume when needed. However, you can still achieve it by having no working deployments which is setting number of replicas to 0.

kubectl scale --replicas=0 deployment/<your-deployment> 

see the help

# Set a new size for a Deployment, ReplicaSet, Replication Controller, or StatefulSet. kubectl scale --help  

Scale also allows users to specify one or more preconditions for the scale action.

If --current-replicas or --resource-version is specified, it is validated before the scale is attempted, and it is guaranteed that the precondition holds true when the scale is sent to the server.

Examples:

  # Scale a replicaset named 'foo' to 3.   kubectl scale --replicas=3 rs/foo    # Scale a resource identified by type and name specified in "foo.yaml" to 3.   kubectl scale --replicas=3 -f foo.yaml    # If the deployment named mysql's current size is 2, scale mysql to 3.   kubectl scale --current-replicas=2 --replicas=3 deployment/mysql    # Scale multiple replication controllers.   kubectl scale --replicas=5 rc/foo rc/bar rc/baz    # Scale statefulset named 'web' to 3.   kubectl scale --replicas=3 statefulset/web 
like image 116
sulabh chaturvedi Avatar answered Oct 16 '22 09:10

sulabh chaturvedi