1.安装bash-completion工具
yum install bash-completion -y
否则报错:
-bash: _get_comp_words_by_ref: command not found
2.执行bash_completion
source /usr/share/bash-completion/bash_completion
3.加载kubectl completion
source <(kubectl completion bash) # 在 bash 中设置当前 shell 的自动补全,要先安装 bash-completion 包。
echo "source <(kubectl completion bash)" >> ~/.bashrc # 在您的 bash shell 中永久的添加自动补全
您还可以为 kubectl
使用一个速记别名,该别名也可以与 completion 一起使用:
alias k=kubectl complete -F __start_kubectl k
验证自动补全的效果(双击 Tab 键):
[root@k8s-master ~]# kubectl
alpha attach completion debug edit help patch rollout top
annotate auth config delete exec kustomize plugin run uncordon
api-resources autoscale cordon describe explain label port-forward scale version
api-versions certificate cp diff expose logs proxy set wait
apply cluster-info create drain get options replace taint
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl create
clusterrole cronjob job priorityclass rolebinding serviceaccount
clusterrolebinding deployment namespace quota secret
configmap ingress poddisruptionbudget role service
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)