If you try to follow the steps in the k8s docs for a MaOS environment you will see that it will not work as expected. Then, follow the steps in order to make it works well.
- Install kubectl, if you do not have it already
$ brew install kubectl
- Install the latest version of bash and
bash-completion.
$ brew install bash
# It will not work with versions < 2
$ brew install bash-completion@2
- Then, add the path
/usr/local/bin/bash
in the/etc/shells
$ sudo echo “
/usr/local/bin/bash
” >/etc/shells
- Set to the installed shell to the current user.
chsh -s /usr/local/bin/bash
- Run:
kubectl completion bash > ~/.kube/kubectl_autocompletion
- Add the following content in the bash_profile (vim ~/.bash_proofile)
# kubectl autocompletion
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fisource ~/.kube/kubectl_autocompletion
Now, after restarting the terminal you will be able to use the kubectl autocomplete with the TAB button. Following an image as an example.
Sponsored by: