Kubernetes (k8s) 管理工具 kubectl 自动补全设置方法

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
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇