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
$ brew install bash
# It will not work with versions < 2
$ brew install bash-completion@2
- Then, add the path
$ sudo echo “
- Set to the installed shell to the current user.
chsh -s /usr/local/bin/bash
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
Now, after restarting the terminal you will be able to use the kubectl autocomplete with the TAB button. Following an image as an example.