# 配置K8s命令自动补全

作者:Odboy (opens new window)

本站地址:https://blog.odboy.cn (opens new window)

# 方法一:临时生效

# 安装bash-completion
## bash-completion-extras需要epel repo源
yum install bash-completion bash-completion-extras -y

# 配置自动补全
source /usr/share/bash-completion/bash_completion

# 临时生效kubectl自动补全
source <(kubectl completion bash)
1
2
3
4
5
6
7
8
9

# 方法二:当前用户生效

# 安装bash-completion
## bash-completion-extras需要epel repo源
yum install bash-completion bash-completion-extras -y

# 配置自动补全
source /usr/share/bash-completion/bash_completion

echo 'source <(crictl completion bash)' >> ~/.bashrc
echo 'source <(kubectl completion bash)' >> ~/.bashrc
source ~/.bashrc
1
2
3
4
5
6
7
8
9
10

# 方法三:全局生效

# 安装bash-completion
## bash-completion-extras需要epel repo源
yum install bash-completion bash-completion-extras -y

# 配置自动补全
source /usr/share/bash-completion/bash_completion

echo 'source <(crictl completion bash)' > /etc/profile.d/k8s.sh
echo 'source <(kubectl completion bash)' >> /etc/profile.d/k8s.sh
source /etc/profile

# 生成kubectl的自动补全脚本
kubectl completion bash >/etc/bash_completion.d/kubectl
1
2
3
4
5
6
7
8
9
10
11
12
13
最近更新: 2024-10-14
2017 - 武林秘籍   |