ZSH completion of Kubectl supplied by minikube or microk8s

If you are using kubectl that is namespaced by minikube or microk8s and refer to kubectl using an alias then completion wont work by default.

This is because zsh expands the alias before attempting completion by default.

So instead of just sourcing the completion command and adding an alias you need to enable the complete_aliases option, so what you need to add to your .zshrc becomes

setopt complete_aliases
alias kubectl='minikube kubectl --'
source <(minikube kubectl completion zsh)

Once you have confirmed this is working, you can output the completion script to an _kubectl file in your completion path to speed things up slightly.

References