how to stop/pause a pod in kubernetes

后端 未结 2 1266
粉色の甜心
粉色の甜心 2021-01-31 07:18

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 conta

相关标签:
2条回答
  • 2021-01-31 07:54

    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
    
    0 讨论(0)
  • 2021-01-31 07:57

    No. It is not possible to stop a pod and resume later when required. however,You can consider the below approach.

    In k8s, pods are abstracted using a service. One way i can think of isolating the pod(s) is by updating the pod selector in service definition. That way you can control the traffic to pod(s) using service definition. Whenever you want to restore the traffic update the pod selector value back to what it was in service definition.

    0 讨论(0)
提交回复
热议问题