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

查看:7550
本文介绍了如何在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 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天全站免登陆