Use the following commands to add the kubectl autocomplete to zsh:
mkdir -p ~/.oh-my-zsh/custom/plugins/kubectl-autocomplete/
kubectl completion zsh > ~/.oh-my-zsh/custom/plugins/kubectl-autocomplete/kubectl-autocomplete.plugin.zsh
After that, edit your ~/.zshrc
to include the plugin kubectl-autocomplete
, like so:
# ~/.zshrc
# ...
plugins=(kubectl-autocomplete)
Kubectx is a great plugin for easily switching namespaces and contexts.
You can install it with these commands:
curl --location --remote-name https://raw.githubusercontent.com/ahmetb/kubectx/master/kubectx
curl --location --remote-name https://raw.githubusercontent.com/ahmetb/kubectx/master/kubens
chmod +x ./{kubectx,kubens}
mv ./{kubectx,kubens} ~/.local/bin/
mkdir --parents ~/.oh-my-zsh/completions
curl --location https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubectx.zsh --output ~/.oh-my-zsh/completions/_kubectx.zsh
curl --location https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubens.zsh --output ~/.oh-my-zsh/completions/_kubens.zsh
echo "fpath=($ZSH/custom/completions $fpath)" >> ~/.zshrc
Press tab after running the commands and you should get suggestions for the output
kubectl g<TAB>
kubectl get p<TAB>
kubens <TAB>
kubectx <TAB>