Kubectl alias

Boost Your Productivity with K8s Aliases

Published on Dec 17, 2020

Reading time: 1 minutes.


Play with kubernets at ease!

Alias? What,Why 🤔


  • An alias is a (usually short) name that the shell translates into another (usually longer) name or command. Aliases allow you to define new commands by substituting a string for the first token of a simple command.
  • It can be used to avoid typing long commands or as a means to correct incorrect input. For common patterns it can reduce keystrokes and improve efficiency. A simple example is setting default options on commands to avoid having to type them each time a command is run
  • ✨ Be lazy - use less keys on your keyboard ✨ 😜

Start your day with a list of things you know you tend to waste time on As Alicia Rades writes on the lifehack

When you notice you’re wasting time, add that time-waster to the automation. This will serve as a reminder of things you shouldn’t allow yourself to do google around commands as an example here.

Let’s get started!

Open your favorite Terminal and run these command.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
alias k=kubectl
alias kl='kubectl logs --tail 100 -f'
alias ke='kubectl get events -o wide'
alias knks='kubectl -n kube-system'
alias knkp='kubectl -n kube-public'
alias kdp='kubectl describe pod'
alias ked='kubectl edit deployment'
alias kr='kubectl get pods -o wide| grep -vE "1/1|2/2|3/3|4/4|Completed"'
alias kr1='kubectl get pods | grep "0/" | grep -Eiv "Completed"'
alias ksc='kubectl get pods -o wide | grep -Eiv "1/1|0/1"'
alias klr='kubectl get deployments -o yaml | grep "path: /api"'
alias kx='function _kx(){ kubectl exec -it $1 sh; };_kx'
alias kt=$(kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}'))

How to use these alias in realtime? 🥳

Below command will follow last 100 line of pods logs with ease 💪🏽.

1
kl podname 

Kubectl official Cheatsheet.