This repository contains a script to generate hundreds of convenient kubectl aliases programmatically.
Some of the 800 generated aliases are:
alias k='kubectl'
alias kg='kubectl get'
alias kgpo='kubectl get pod'
alias ksysgpo='kubectl --namespace=kube-system get pod'
alias krm='kubectl delete'
alias krmf='kubectl delete -f'
alias krming='kubectl delete ingress'
alias krmingl='kubectl delete ingress -l'
alias krmingall='kubectl delete ingress --all-namespaces'
alias kgsvcoyaml='kubectl get service -o=yaml'
alias kgsvcwn='watch kubectl get service --namespace'
alias kgsvcslwn='watch kubectl get service --show-labels --namespace'
alias kgwf='watch kubectl get -f'
...
See the full list.
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
Print the full command before running it: Add this to your .bashrc
or
.zshrc
file:
function kubectl() { echo "+ kubectl $@">&2; command kubectl $@; }
k
=kubectl
sys
=--namespace kube-system
- commands:
g
=get
d
=describe
rm
=delete
a
:apply -f
ex
:exec -i -t
lo
: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
:--all
or--all-namespaces
depending on the commandsl
:--show-labels
w
=-w/--watch
- output format:
- value flags (should be at the end):
n
=-n/--namespace
f
=-f/--filename
l
=-l/--selector
-
Doesn't this slow down my shell start up? Sourcing the file that contains ~500 aliases 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.
This is not an official Google project.