Kubectl Autocomplete

Recently, we migrated our development environment from Docker Compose to Kubernetes.

Kubernetes has a command line interface for managing its clusters called kubectl.

As you probably guessed from the title, today I learned how to configure autocompletion for kubectl.

Kubernetes Logo


Depends on the shell you’re using.


Add the following to your .zshrc file:

source <(kubectl completion zsh)  # setup autocomplete in zsh into the current shell
echo "if [ $commands[kubectl] ]; then source <(kubectl completion zsh); fi" >> ~/.zshrc # add autocomplete permanently to your zsh shell

If you’re using oh-my-zsh you can use this plugin by adding kubectl to the plugins array in your .zshrc:

plugins=(... kubectl)


Add the following to your .bashrc or bash_profile:



Shahar Kedar pointed me to this repo.

Pro Tip

If you haven’t already, define this time-saving alias:

alias k="kubectl"
comments powered by Disqus