kubectl completion
概要
为指定 shell (bash, zsh, fish, 或 powershell) 输出 shell 补全代码。该 shell 代码必须被评估才能提供 kubectl 命令的交互式补全。这可以通过从 .bash_profile 中 source 它来实现。
详细说明如何执行此操作的文档在此处
for macOS:
https://kubernetes.ac.cn/docs/tasks/tools/install-kubectl-macos/#enable-shell-autocompletion
for linux:
https://kubernetes.ac.cn/docs/tasks/tools/install-kubectl-linux/#enable-shell-autocompletion
for windows:
https://kubernetes.ac.cn/docs/tasks/tools/install-kubectl-windows/#enable-shell-autocompletion
致 zsh 用户注意事项:[1] zsh 补全功能仅在 zsh 版本 >= 5.2 时才支持。
kubectl completion SHELL
示例
# Installing bash completion on macOS using homebrew
## If running Bash 3.2 included with macOS
brew install bash-completion
## or, if running Bash 4.1+
brew install bash-completion@2
## If kubectl is installed via homebrew, this should start working immediately
## If you've installed via other means, you may need add the completion to your completion directory
kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl
# Installing bash completion on Linux
## If bash-completion is not installed on Linux, install the 'bash-completion' package
## via your distribution's package manager.
## Load the kubectl completion code for bash into the current shell
source <(kubectl completion bash)
## Write bash completion code to a file and source it from .bash_profile
kubectl completion bash > ~/.kube/completion.bash.inc
printf "
# kubectl shell completion
source '$HOME/.kube/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile
# Load the kubectl completion code for zsh[1] into the current shell
source <(kubectl completion zsh)
# Set the kubectl completion code for zsh[1] to autoload on startup
kubectl completion zsh > "${fpath[1]}/_kubectl"
# Load the kubectl completion code for fish[2] into the current shell
kubectl completion fish | source
# To load completions for each session, execute once:
kubectl completion fish > ~/.config/fish/completions/kubectl.fish
# Load the kubectl completion code for powershell into the current shell
kubectl completion powershell | Out-String | Invoke-Expression
# Set kubectl completion code for powershell to run on startup
## Save completion code to a script and execute in the profile
kubectl completion powershell > $HOME\.kube\completion.ps1
Add-Content $PROFILE "$HOME\.kube\completion.ps1"
## Execute completion code in the profile
Add-Content $PROFILE "if (Get-Command kubectl -ErrorAction SilentlyContinue) {
kubectl completion powershell | Out-String | Invoke-Expression
}"
## Add completion code directly to the $PROFILE script
kubectl completion powershell >> $PROFILE
可选项
-h, --help | |
completion 命令的帮助信息 |
继承的父级选项
--as string | |
执行操作时要模拟的用户名。用户可以是普通用户,也可以是命名空间中的 ServiceAccount。 | |
--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 的容忍秒数 (tolerationSeconds)。 | |
--default-unreachable-toleration-seconds int Default: 300 | |
表示添加到每个尚未有此类容忍度的 Pod 上的默认容忍度 unreachable:NoExecute 的容忍秒数 (tolerationSeconds)。 | |
--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" | |
要捕获的 profile 名称。可以是 (none|cpu|heap|goroutine|threadcreate|block|mutex) 之一。 | |
--profile-output string Default: "profile.pprof" | |
写入 profile 的文件名 | |
--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 项目的其他地方进行。