k8s kubectl 自动补全

CentOS:

1
2
3
4
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

MacOS:

1
2
$ brew install bash-completion
$ kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl

参考:

https://kubernetes.io/docs/tasks/tools/#enabling-shell-autocompletion

https://github.com/xujiyou/blog-data/blob/master/%E4%BA%91%E5%8E%9F%E7%94%9F/Kubernetes/K8sFAQ.md