KUBERNETES(1)(kubernetes)

πŸ’– KUBERNETES(1)(kubernetes) πŸ’–

okay bestie, pull up a chair, we're doing kubectl completion and honestly? it's a glow-up for your terminal. this page lives in the kubectl family of manual pages (manual name kubernetes, section 1), originally written by Eric Paris back in Jan 2015 ✨


✨ NAME ✨

kubectl completion β€” spits out shell completion code for whichever shell you're living in (bash, zsh, fish, or powershell) 🐚


🌸 SYNOPSIS 🌸

kubectl completion [OPTIONS]

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically: this command outputs shell completion code for the shell you specify β€” and your options are bash, zsh, fish, or powershell. ✨

Here's the tea though: that output doesn't do anything on its own. you have to evaluate the shell code for it to actually give you interactive completion of kubectl commands. one way to do that is sourcing it from your .bash_profile. no cap.

the detailed how-to lives right here, and there's a version for each platform:

πŸ“ note for zsh girlies: [1] zsh completions are only supported in versions of zsh >= 5.2. if you're on something older, that's a you problem, and by "you problem" i mean an upgrade πŸ’…

πŸ‘‘ OPTIONS INHERITED FROM PARENT COMMANDS πŸ‘‘

these aren't even this command's own flags, they're inherited from the parent, and they're iconic:

  • --as="" β€” username to impersonate for the operation. user could be a regular user or a service account in a namespace.
  • --as-group=[] β€” group to impersonate for the operation. this flag can be repeated to specify multiple groups. 🫢
  • --as-uid="" β€” UID to impersonate for the operation.
  • --as-user-extra=[] β€” user extras to impersonate for the operation. this flag can be repeated to specify multiple values for the same key.
  • --cache-dir="/home/username/.kube/cache" β€” default cache directory πŸ“
  • --certificate-authority="" β€” path to a cert file for the certificate authority
  • --client-certificate="" β€” path to a client certificate file for TLS
  • --client-key="" β€” path to a client key file for TLS
  • --cluster="" β€” the name of the kubeconfig cluster to use
  • --context="" β€” the name of the kubeconfig context to use
  • --disable-compression=false β€” if true, opt-out of response compression for all requests to the server
  • --insecure-skip-tls-verify=false β€” if true, the server's certificate will not be checked for validity. this will make your HTTPS connections insecure. 🚨 like, actually insecure. tread carefully.
  • --kubeconfig="" β€” path to the kubeconfig file to use for CLI requests.
  • --kuberc="" β€” path to the kuberc file to use for preferences. this can be disabled by exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=off.
  • --match-server-version=false β€” require server version to match client version
  • -n, --namespace="" β€” if present, the namespace scope for this CLI request
  • --password="" β€” password for basic authentication to the API server
  • --profile="none" β€” name of profile to capture. one of (none|cpu|heap|goroutine|threadcreate|block|mutex|trace)
  • --profile-output="profile.pprof" β€” name of the file to write the profile to
  • --proxy-url="" β€” proxy URL to use for requests to the API server
  • --request-timeout="0" β€” the length of time to wait before giving up on a single server request. non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). a value of zero means don't timeout requests. ⏳
  • -s, --server="" β€” the address and port of the Kubernetes API server
  • --tls-server-name="" β€” server name to use for server certificate validation. if it is not provided, the hostname used to contact the server is used
  • --token="" β€” bearer token for authentication to the API server
  • --user="" β€” the name of the kubeconfig user to use
  • --username="" β€” username for basic authentication to the API server
  • --version=false β€” --version, --version=raw prints version information and quits; --version=vX.Y.Z... sets the reported version
  • --warnings-as-errors=false β€” treat warnings received from the server as errors and exit with a non-zero exit code

🌈 EXAMPLE 🌈

okay this block is a whole journey, but it's the good kind. copy it exactly, character for character, no freestyling bestie:

# Installing bash completion on macOS using homebrew
## If running Bash 3.2 included with macOS
brew install bash-completion
## or, if running Bash 4.1+
brew install bash-completion@2
## If kubectl is installed via homebrew, this should start working immediately
## If you've installed via other means, you may need add the completion to your completion directory
kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl

# Installing bash completion on Linux
## If bash-completion is not installed on Linux, install the 'bash-completion' package
## via your distribution's package manager.
## Load the kubectl completion code for bash into the current shell
source <(kubectl completion bash)
## Write bash completion code to a file and source it from .bash_profile
kubectl completion bash > ~/.kube/completion.bash.inc
printf "
# kubectl shell completion
source '$HOME/.kube/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile

# Load the kubectl completion code for zsh[1] into the current shell
source <(kubectl completion zsh)
# Set the kubectl completion code for zsh[1] to autoload on startup
kubectl completion zsh > "${fpath[1]}/_kubectl"

# Load the kubectl completion code for fish[2] into the current shell
kubectl completion fish | source
# To load completions for each session, execute once:
kubectl completion fish > ~/.config/fish/completions/kubectl.fish

# Load the kubectl completion code for powershell into the current shell
kubectl completion powershell | Out-String | Invoke-Expression
# Set kubectl completion code for powershell to run on startup
## Save completion code to a script and execute in the profile
kubectl completion powershell > "$HOME\.kube\completion.ps1"
Add-Content $PROFILE ". '$HOME\.kube\completion.ps1'"
## Execute completion code in the profile
Add-Content $PROFILE "if (Get-Command kubectl -ErrorAction SilentlyContinue) {
kubectl completion powershell | Out-String | Invoke-Expression
}"
## Add completion code directly to the $PROFILE script
kubectl completion powershell >> $PROFILE

πŸŽ€ SEE ALSO πŸŽ€


πŸ’œ HISTORY πŸ’œ

January 2015, originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material β€” but hopefully they have been automatically generated since! 😌


and that's the whole page, bestie πŸ’– this one came out of the Manuals corner of the world, sitting in the User section, stamped with the manual name KUBERNETES(1)(kubernetes) β€” go forth and autocomplete, you absolute icon 🫢✨

πŸ“¦ where this page comes from