0%

K8S命令tab补全

配置k8s命令tab补全并设置别名

1
2
3
4
5
6
7
8
yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
# 设置kubectl别名为k
echo "alias k=kubectl" >> ~/.bashrc
#这句不加的话用kubectl可以使用Tab键自动补全,但是别名k不能使用Tab键自动补全
echo "complete -F __start_kubectl k >> ~/.bashrc

source ~/.bashrc

输入“k ge[tab] no[tab]”效果如下

1
2
3
4
5
6
7
[root@k8s-master01 ~]# k get nodes
NAME STATUS ROLES AGE VERSION
k8s-master01 Ready control-plane 5d15h v1.26.3
k8s-master02 Ready control-plane 5d15h v1.26.3
k8s-master03 Ready control-plane 5d15h v1.26.3
k8s-node01 Ready <none> 5d15h v1.26.3
k8s-node02 Ready <none> 5d15h v1.26.3