Kubernetes kubectl scale 命令详解

kubectl scale

扩容或缩容 Deployment、ReplicaSet、Replication Controller或 Job 中Pod数量。

scale也可以指定多个前提条件,如:当前副本数量或 --resource-version ,进行伸缩比例设置前,系统会先验证前提条件是否成立。

语法

$ scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)

示例

将名为foo中的pod副本数设置为3。

kubectl scale --replicas=3 rs/foo

将由“foo.yaml”配置文件中指定的资源对象和名称标识的Pod资源副本设为3。

kubectl scale --replicas=3 -f foo.yaml

如果当前副本数为2,则将其扩展至3。

kubectl scale --current-replicas=2 --replicas=3 deployment/mysql

设置多个RC中Pod副本数量。

kubectl scale --replicas=5 rc/foo rc/bar rc/baz

Flags

Name Shorthand Default Usage
current-replicas -1 Precondition for current size. Requires that the current size of the resource match this value in order to scale.
filename f [] Filename, directory, or URL to files identifying the resource to set a new size
include-extended-apis true If true, include definitions of new APIs via calls to the API server. [default true]
output o Output mode. Use "-o name" for shorter output (resource/name).
record false Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
replicas -1 The new desired number of replicas. Required.
resource-version Precondition for resource version. Requires that the current resource version match this value in order to scale.
timeout 0s The length of time to wait before giving up on a scale operation, zero means don't wait. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).
K8S中文社区微信公众号

Kubernetes kubectl rollout undo 命令详解

kubectl rollout undo

回滚到之前的版本。

语法

$ undo (TYPE NAME | TYPE/NAME) [flags]

示例

回滚到之前的deployment版本

kubectl rollout undo deployment/abc
kubectl rollout undo --dry-run=true deployment/abc

回滚到daemonset 修订3版本

kubectl rollout undo daemonset/abc --to-revision=3

Flags

Name Shorthand Default Usage
dry-run false If true, only print the object that would be sent, without sending it.
filename f [] Filename, directory, or URL to files identifying the resource to get from a server.
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
to-revision 0 The revision to rollback to. Default to 0 (last revision).

 

K8S中文社区微信公众号

Kubernetes kubectl rollout status 命令详解

kubectl rollout status

查看资源的状态。

使用—watch = false 来查看当前状态,需要查看特定修订版本状态 请使用--revision = N 来指定。

语法

$ status (TYPE NAME | TYPE/NAME) [flags]

示例

查看deployment的状态

kubectl rollout status deployment/nginx

Flags

Name Shorthand Default Usage
filename f [] Filename, directory, or URL to files identifying the resource to get from a server.
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
revision 0 Pin to a specific revision for showing its status. Defaults to 0 (last revision).
watch w true Watch the status of the rollout until it's done.

 

K8S中文社区微信公众号

Kubernetes kubectl rollout resume 命令详解

kubectl rollout resume

恢复已暂停的资源

pause命令暂停的资源将不会被控制器协调使用。可以通过resume来恢复资源。目前仅支持恢复deployment资源。

语法

$ resume RESOURCE

示例

恢复已暂停的 deployment

kubectl rollout resume deployment/nginx

Flags

Name Shorthand Default Usage
filename f [] Filename, directory, or URL to files identifying the resource to get from a server.
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.

 

K8S中文社区微信公众号

Kubernetes kubectl rollout pause 命令详解

kubectl rollout pause

将提供的资源标记为暂停

被pause命令暂停的资源不会被控制器协调使用,可以是“kubectl rollout resume”命令恢复已暂停资源。

目前仅支持的资源:deployments。

语法

$ pause RESOURCE

示例

将deployment标记为暂停。#只要deployment在暂停中,使用deployment更新将不会生效。

kubectl rollout pause deployment/nginx

Flags

Name Shorthand Default Usage
filename f [] Filename, directory, or URL to files identifying the resource to get from a server.
recursive R false Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.

 

K8S中文社区微信公众号