如何在 kubernetes 中停止/暂停 Pod [英] how to stop/pause a pod in kubernetes

查看:313
本文介绍了如何在 kubernetes 中停止/暂停 Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的集群中运行了一个 MySQL pod.
我需要暂时暂停 pod 的工作而不删除它,类似于 docker,其中 docker stop container-id cmd 将停止容器不会删除容器.
kubernetes 中是否有任何命令可以暂停/停止 Pod?

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?

推荐答案

因此,正如其他人指出的那样,Kubernetes 不支持停止/暂停 pod 的当前状态并在需要时恢复.但是,您仍然可以通过没有将副本数设置为 0 的工作部署来实现它.

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>

查看帮助

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

Scale 还允许用户为缩放操作指定一个或多个先决条件.

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

如果指定了 --current-replicas--resource-version,则在尝试缩放之前对其进行验证,并且是保证当秤发送到服务器时前提条件成立.

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 中停止/暂停 Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆