kubectl-completion
Enable shell completion for kubectl commands
TLDR
Print the completion script for Bash, Zsh, fish, or PowerShell
Load Bash or Zsh completions into the current shell session
Append Bash completion script to ~/.bashrc
Write Zsh completion script to a file in the fpath
Load fish completions into the current shell session
Persist fish completions
Load PowerShell completions into the current shell session
Persist PowerShell completions
SYNOPSIS
kubectl completion bash|zsh|fish|powershell|cmd [--no-descriptions] [-h, --help]
PARAMETERS
-h, --help
Display help for completion
--no-descriptions
Omit completion descriptions for faster scripts
DESCRIPTION
kubectl completion generates shell-specific autocompletion scripts for the kubectl Kubernetes CLI, supporting Bash, Zsh, Fish, PowerShell, and CMD. It outputs code to stdout that enables intelligent tab-completion for subcommands, resources, namespaces, labels, and cluster-state data via API queries.
This dynamic completion reduces errors and speeds up workflows. Install by piping output to the shell's completion directory:
- Bash:
kubectl completion bash > /etc/bash_completion.d/kubectl - Zsh:
kubectl completion zsh > ${fpath[1]}/_kubectl
Source the file or restart the shell. The --no-descriptions flag skips verbose hints for faster loading. Ideal for Linux environments, it integrates with package managers like bash-completion on Ubuntu/Fedora.
CAVEATS
Requires kubectl in PATH for dynamic sourcing. Generated files are static; re-run after kubectl upgrades. Zsh/Fish may need compinit reload.
BASH DYNAMIC SOURCING
Add to ~/.bashrc:source <(kubectl completion bash)
ZSH PERMANENT INSTALL
kubectl completion zsh > "${fpath[1]}/_kubectl"
Then compinit
HISTORY
Introduced in Kubernetes v1.3.0 (March 2016) to boost CLI productivity; expanded shell support in later releases like v1.23+ for Fish/PowerShell.
SEE ALSO
kubectl(1)


