KUBECTL Autocomplete and Aliases: Use the following to enable auto-completion for kubectl on MAC.
- William B

- Aug 5
- 1 min read

ZSH Autocomplete
Run the following on your terminal:
% source <(kubectl completion zsh) If you are getting the error:
/dev/fd/11:2: command not found: compdefYou might need to activate the completion system. Run the following on your terminal:
$ autoload -Uz compinit$ compinit$ source <(kubectl completion zsh)$ echo "[[ $commands[kubectl] ]] && source <(kubectl completion zsh)" >> ~/.zshrcNow you can use tab for auto-completion of kubectl commands.
Alias
You can create aliases and add them to your ~/.zshrc file, for example:
alias k="kubectl"
alias kgtkc="kubectl get tkc -A -o"
alias kgp="kubectl get pods"
alias kg="kubectl get"
alias kge="kubectl get events"
alias kd="kubectl describe"
Custom:
columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,PHASE:status.phase,CREATIONTIME:metadata.creationTimestamp,VERSION:spec.distribution.fullVersion,CP:spec.topology.controlPlane.replicas,WORKER:status.totalWorkerReplicas --sort-by="metadata.creationTimestamp"'Adding and saving the above in your ~/.zshrc file, make sure you relaunch the terminal. Now you are ready to use the aliases.




Comments