Working with Kubernetes has made managing containerized microservices much easier for us. However, working with the Kubernetes client, kubectl, can be a little cumbersome, so I use some aliases to speed things up. If you aren’t familiar with Kubernetes and kubectl, Google can explain much better than I can.

alias k="kubectl"
alias kd="kubectl describe"
alias kg="kubectl get"
alias kc="kubectl create"
alias kdel="kubectl delete"
alias ke="kubectl exec -it"
alias kdes="kubectl describe"
alias kl="kubectl logs"

With these, combined with the abbreviations built into kubectl, kubectl get pods is shortened to kg po. From 16 characters to 5! Trust me, that savings adds up very quickly.

Another thing that slowed me down at first was having to specify the namespace for a command. Luckily you can change the assumed namespace. I have a bash function that takes the namespace name as an argument.

setns() {
export CONTEXT=$(kubectl config view | grep current-context | awk '{print $2}')
kubectl config set-context $CONTEXT --namespace=$1

So for instance, setns production. Now kubectl will default to that namespace unless you explicitly state a different one.

Hopefully these tips make working with kubectl a little more painless.