Skip to content

Instantly share code, notes, and snippets.

@GusAntoniassi
Last active June 20, 2026 02:40
Show Gist options
  • Select an option

  • Save GusAntoniassi/2f58e716b67f648d13f91c1d780b05bf to your computer and use it in GitHub Desktop.

Select an option

Save GusAntoniassi/2f58e716b67f648d13f91c1d780b05bf to your computer and use it in GitHub Desktop.
Configure autocompletion to kubectl with zsh

kubectl with ZSH (oh-my-zsh)

How to configure

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)

Optional: kubens and kubectx

Kubectx is a great plugin for easily switching namespaces and contexts.

You can install it with these commands:

curl -LO https://raw.githubusercontent.com/ahmetb/kubectx/master/kubectx
curl -LO https://raw.githubusercontent.com/ahmetb/kubectx/master/kubens

sudo chmod +x ./{kubectx,kubens}
sudo mv ./{kubectx,kubens} /usr/local/bin/

mkdir -p ~/.oh-my-zsh/completions
curl -L https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubectx.zsh -o ~/.oh-my-zsh/completions/_kubectx.zsh
curl -L https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubens.zsh -o ~/.oh-my-zsh/completions/_kubens.zsh

How to use it

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>
@miRemid

miRemid commented Jul 11, 2023

Copy link
Copy Markdown

Thank you, it works :D

@ejaysss

ejaysss commented Feb 5, 2024

Copy link
Copy Markdown

Thanks! It works!

@sssyybil

Copy link
Copy Markdown

Thanks!

@saireddyb

Copy link
Copy Markdown

Thanks

@satoshimum

Copy link
Copy Markdown

Awsome

@dukercs

dukercs commented Feb 14, 2026

Copy link
Copy Markdown

Awesome! Thks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment