kubectl-aliases
June 21, 2026 · View on GitHub
This repository contains a script to generate hundreds of convenient shell aliases for kubectl, so you no longer need to spell out every single command and --flag over and over again.
An example shell alias created from command/flags permutation looks like:
alias ksysgdepwslowidel='kubectl --namespace=kube-system get deployment --watch --show-labels -o=wide -l'
Confused? Read on.
Examples
Some of the generated aliases are:
alias k='kubectl'
alias kg='kubectl get'
alias kgpo='kubectl get pods'
alias ksysgpo='kubectl --namespace=kube-system get pods'
alias krm='kubectl delete'
alias krmf='kubectl delete --recursive -f'
alias krming='kubectl delete ingress'
alias krmingl='kubectl delete ingress -l'
alias krmingall='kubectl delete ingress --all'
alias kgsvcoyaml='kubectl get service -o=yaml'
alias kgsvcwn='kubectl get service --watch --namespace'
alias kgposlwn='kubectl get pods --show-labels --watch --namespace'
alias kgwf='kubectl get --watch --recursive -f'
...
See the full list.
Installation
You can directly download the .kubectl_aliases file
and save it in your $HOME directory, then edit your .bashrc/.zshrc file with:
[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases
Recommendation: If you want to use GNU
watchcommand instead ofkubectl [...] --watch, run it like this:[ -f ~/.kubectl_aliases ] && source \ <(cat ~/.kubectl_aliases | sed -r 's/(kubectl.*) --watch/watch \1/g')
Print the full command before running it: Add this to your .bashrc or
.zshrc file:
function kubectl() { echo "+ kubectl $@">&2; command kubectl $@; }
Syntax explanation
k=kubectlsys=--namespace kube-system
- commands:
g=getd=describerm=deletea:apply --recursive -fak:apply -kk:kustomizeex:exec -i -tlo:logs -f
- resources:
po=pod,dep=deployment,ing=ingress,svc=service,cm=configmap,sec=secret,ns=namespace,no=node
- flags:
- output format:
oyaml,ojson,owide all:--allor--all-namespacesdepending on the commandsl:--show-labelsw=-w/--watch
- output format:
- value flags (should be at the end):
n=-n/--namespacef=-f/--filenamel=-l/--selector
FAQ
-
Doesn't this slow down my shell start up? Sourcing the generated alias file takes about 30-45 milliseconds in my shell (zsh). I don't think it's a big deal for me. Measure it with
echo $(($(date +%s%N)/1000000))command yourself in your .bashrc/.zshrc. -
Can I add more Kubernetes resource types to this? Please consider forking this repo and adding the resource types you want. Not all resource types are used by everyone, and adding more resource types slows down shell initialization see above).
-
Where can I find PowerShell aliases for kubectl? There’s a fork of this here.
Authors
This is not an official Google project.