Ubuntu部署的k8s集群kubectl tab补全报错
kubectl tab时报错:bash: _get_comp_words_by_ref: command not found
·
环境信息:
- Ubuntu2204
- k8s: v1.27.5
问题现象:想要实现kubectl tab补全效果。报错:bash: _get_comp_words_by_ref: command not found
解决步骤:
- 安装 bash-completion
安装apt install bash-completion
假如出现以下提示,需要先执行'apt --fix-broken install
这个命令处理依赖性
root@k8s-node2:~# apt-get install bash-completion
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libexpat1-dev : Depends: libexpat1 (= 2.4.7-1ubuntu0.3) but 2.4.7-1ubuntu0.2 is to be installed
libpython3.10 : Depends: libpython3.10-stdlib (= 3.10.12-1~22.04.3) but 3.10.6-1~22.04.2ubuntu1 is to be installed
libpython3.10-dev : Depends: libpython3.10-stdlib (= 3.10.12-1~22.04.3) but 3.10.6-1~22.04.2ubuntu1 is to be installed
python3.10-dev : Depends: python3.10 (= 3.10.12-1~22.04.3) but 3.10.6-1~22.04.2ubuntu1 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
- 执行bash_completion并重新加载kubectl completion,执行完成后就可以tab补全kubectl命令了
root@k8s-node2:~#source /usr/share/bash-completion/bash_completion;source <(kubectl completion bash)
- 添加命令到Bash配置文件,以便每次打开新的Bash shell时都能够启用kubectl命令的自动补全功能
echo "source /usr/share/bash-completion/bash_completion;source <(kubectl completion bash)" >> ~/.bashrc # 在你的 bash shell 中永久地添加自动补全
更多推荐
已为社区贡献1条内容
所有评论(0)