I followed the instructions for installing Bash completion as given by kubectl completion -h:
bash-completion via Homebrew~/.bashrc, I first source bash-completion then output from the completion kubectl subcommand:source $(brew --prefix)/etc/bash_completionsource <(kubectl completion bash)With these in place, I start up a new shell but the completion doesn't work. How do I get it working?
See the "On macOS, using bash" section of kubectl documentation: https://kubernetes.io/docs/tasks/tools/install-kubectl/#on-macos-using-bash I recently contributed those so they should be up to date. If not, please send a pull request to fix it.
Also: https://blog.fabric8.io/enable-bash-completion-for-kubernetes-with-kubectl-506bc89fe79e
After brew install bash-completion, to actually enable bash completions, you need to:
source /usr/local/etc/profile.d/bash_completion.shAdd that line to you bashrc.
Then you can:
source <(kubectl completion bash)Once bash-completion is installed by Homebrew, it appears that its completions need to reside in $(brew --prefix)/etc/bash_completion.d. There you'll find a lot of other completions that come bundled. To add the completion for kubectl:
$ kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectlThat did the trick for me.
I the answer form Ahmet B, the fix says to add the following to your .bashrc file:
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"However, the install of completions 2:
brew install bash-completion@2finishes with a message to add the export line if you would LIKE TO USE V1 completions. Removing that export enabled kubectl completion for me.