K8S Utility No. 6 - kubectl-aliases

This article was last updated on: July 24, 2024 am

Opening

📜 introduction

  • Sharpen knives and do not chop wood by mistake
  • Better tools make good work

ahmetb/kubectl-aliases

It isA whole lotThe purpose of kubectl alias is to save time typing a long list of kubectl commands.

The address is here:ahmetb/kubectl-aliases

example

For example:

1
alias ksysgdepwslowidel='kubectl --namespace=kube-system get deployment --watch --show-labels -o=wide -l'

How many are complete, nearly 800… Here are just a few of them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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='kubectl get service --watch --namespace'
alias kgsvcslwn='kubectl get service --show-labels --watch --namespace'

alias kgwf='kubectl get --watch -f'
...

See the full listOver here

Installation

You can download bash/zsh directly.kubectl_aliasesfile and save to yours$HOMEDirectory.

Then add to .bashrc/.zshrc Middle:

1
[ -f ~/.kubectl_aliases ] && source ~/.kubectl_aliases

Abbreviation explained

  • k= kubectl
    • sys=--namespace kube-system
  • commands:
    • g=get
    • d=describe
    • rm=delete
    • a:apply -f
    • ak:apply -k
    • k:kustomize
    • 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 command
    • sl: --show-labels
    • w=-w/--watch
  • value flags (should be at the end):
    • n=-n/--namespace
    • f=-f/--filename
    • l=-l/--selector

That’s All

🎉🎉🎉

ahmetb/kubectl-aliases