如何在kubernetes中stop/pause(停止/暂停)一个pod

识趣 发表于: 2021-12-08   最后更新时间: 2021-12-08 17:32:37   7,671 游览

我的集群中运行了一个 MySQL pod。

我需要暂时暂停 pod 的工作而不删除它,类似于 docker,其中docker stop container-id cmd 将停止容器而不是删除容器。

kubernetes 中是否有任何命令可以暂停/停止 Pod吗?

发表于 2021-12-08

Kubernetes不支持停止/暂停pod的当前状态并在需要时恢复。但是,你可以将副本数量设置为0,来实现这样的效果。

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

见帮助

# 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.

例子:

# 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
你的答案

查看kubernetes相关的其他问题或提一个您自己的问题