kubectl autoscale

概要

创建一个自动伸缩器,用于自动选择和设置在 Kubernetes 集群中运行的 Pod 数量。该命令将首先尝试使用 autoscaling/v2 API,如果出错,将回退到 autoscaling/v1 API。

按名称查找 Deployment、ReplicaSet、StatefulSet 或 ReplicationController,并创建一个使用给定资源作为参考的自动伸缩器。自动伸缩器可以根据需要自动增加或减少系统中部署的 Pod 数量。

kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU]

示例

  # Auto scale a deployment "foo", with the number of pods between 2 and 10, no target CPU utilization specified so a default autoscaling policy will be used
  kubectl autoscale deployment foo --min=2 --max=10
  
  # Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%
  kubectl autoscale rc foo --max=5 --cpu-percent=80

选项

--allow-missing-template-keys     Default: true

如果为 true,当模板中缺少字段或 map 键时,忽略模板中的任何错误。仅适用于 golang 和 jsonpath 输出格式。

--cpu-percent int32     Default: -1

所有 Pod 的目标平均 CPU 利用率(以请求的 CPU 百分比表示)。如果未指定或为负,将使用默认的自动伸缩策略。

--dry-run string[="unchanged"]     Default: "none"

必须是 "none"、"server" 或 "client"。如果是客户端策略,只打印将要发送的对象,而不实际发送。如果是服务器策略,则提交服务器端请求,但不持久化资源。

--field-manager string     Default: "kubectl-autoscale"

用于跟踪字段所有权的管理器的名称。

-f, --filename strings

指定要自动伸缩资源的文件的文件名、目录或 URL。

-h, --help

autoscale 的帮助

-k, --kustomize string

处理 kustomization 目录。此标志不能与 -f 或 -R 一起使用。

--max int32     Default: -1

自动伸缩器可以设置的 Pod 数量上限。必需。

--min int32     Default: -1

自动伸缩器可以设置的 Pod 数量下限。如果未指定或为负,服务器将应用默认值。

--name string

新创建对象的名称。如果未指定,将使用输入资源的名称。

-o, --output string

输出格式。可选值之一:(json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file)。

-R, --recursive

递归处理 -f, --filename 中使用的目录。当你想管理组织在同一目录中的相关清单时非常有用。

--save-config

如果为 true,当前对象的配置将保存在其 annotation 中。否则,annotation 将保持不变。当将来想要对此对象执行 kubectl apply 时,此标志很有用。

--show-managed-fields

如果为 true,在以 JSON 或 YAML 格式打印对象时保留 managedFields。

--template string

当 -o=go-template, -o=go-template-file 时使用的模板字符串或模板文件路径。模板格式为 golang 模板 [https://golang.ac.cn/pkg/text/template/#pkg-overview]。

继承的父选项

--as string

用于模拟执行操作的用户名。用户可以是普通用户或命名空间中的 Service Account。

--as-group strings

用于模拟执行操作的组,此标志可以重复以指定多个组。

--as-uid string

用于模拟执行操作的 UID。

--cache-dir string     Default: "$HOME/.kube/cache"

默认缓存目录

--certificate-authority string

证书颁发机构证书文件的路径

--client-certificate string

客户端 TLS 证书文件的路径

--client-key string

客户端 TLS 密钥文件的路径

--cluster string

要使用的 kubeconfig 集群的名称

--context string

要使用的 kubeconfig 上下文的名称

--default-not-ready-toleration-seconds int     Default: 300

指示未就绪的 Pod 的默认容忍度 notReady:NoExecute 的容忍秒数,默认添加到每个尚未具有此类容忍度的 Pod。

--default-unreachable-toleration-seconds int     Default: 300

指示不可到达的 Pod 的默认容忍度 unreachable:NoExecute 的容忍秒数,默认添加到每个尚未具有此类容忍度的 Pod。

--disable-compression

如果为 true,则对所有发送到服务器的请求禁用响应压缩。

--insecure-skip-tls-verify

如果为 true,则不检查服务器证书的有效性。这将使你的 HTTPS 连接不安全。

--kubeconfig string

用于 CLI 请求的 kubeconfig 文件路径。

--match-server-version

要求服务器版本与客户端版本匹配

-n, --namespace string

如果存在,此 CLI 请求的命名空间范围

--password string

用于 API 服务器基本认证的密码

--profile string     Default: "none"

要捕获的性能分析文件名。可选值之一:(none|cpu|heap|goroutine|threadcreate|block|mutex)

--profile-output string     Default: "profile.pprof"

写入性能分析的文件名

--request-timeout string     Default: "0"

等待单个服务器请求的超时时间。非零值应包含相应的时间单位(例如,1s、2m、3h)。零值表示请求不超时。

-s, --server string

Kubernetes API 服务器的地址和端口

--storage-driver-buffer-duration duration     Default: 1m0s

存储驱动中的写操作将在此持续时间内进行缓冲,并作为单个事务提交到非内存后端。

--storage-driver-db string     Default: "cadvisor"

数据库名称

--storage-driver-host string     Default: "localhost:8086"

数据库主机:端口

--storage-driver-password string     Default: "root"

数据库密码

--storage-driver-secure

使用安全连接连接数据库

--storage-driver-table string     Default: "stats"

表名

--storage-driver-user string     Default: "root"

数据库用户名

--tls-server-name string

用于服务器证书验证的服务器名称。如果未提供,则使用联系服务器时使用的主机名。

--token string

用于 API 服务器认证的 Bearer Token

--user string

要使用的 kubeconfig 用户的名称

--username string

用于 API 服务器基本认证的用户名

--version version[=true]

--version, --version=raw 打印版本信息并退出;--version=vX.Y.Z... 设置报告的版本

--warnings-as-errors

将从服务器收到的警告视为错误并以非零退出代码退出。

另请参阅

  • kubectl - kubectl 控制 Kubernetes 集群管理器

本页面是自动生成的。

如果你打算报告此页面的问题,请在你的问题描述中提及该页面是自动生成的。修复可能需要在 Kubernetes 项目的其他地方进行。

上次修改于 2025 年 4 月 24 日太平洋标准时间 8:03:v1.33 的 kubectl 参考 (80481646c3)