Kubectl tips, tricks, and alias’ to make your life easier

  • by
kubectl kubernetes alias and functions
kubectl kubernetes alias and functions

Tip 1: Setup Autocomplete with Kubectl

Using Bash

Add the following to your ~/.bashrc file:

source <(kubectl completion bash)

Using ZSH

Add the following to your ~/.bashrc file:

source <(kubectl completion zsh)

Tip 2: Setup some alias’

It will take some time to get into the habit of using them, but your future self will thank you. To use these, add the following to your ~/.bashrc file:

alias k='kubectl'
alias kg='kubectl get'
alias ka='kubectl apply'
alias kd='kubectl describe'
alias kl='kubectl logs'
alias kgp='kubectl get pods'
alias kgs='kubectl get secrets'
alias kgsrv='kubectl get service'
alias kgd='kubectl get deployments'
alias kdp='kubectl describe pods'
alias kgi='kubectl get ingress'

Tip 3: Add a bash function to get a pod in the network

Add the following to your ~/.bashrc file:

function alpine_box {
  kubectl run -i --rm --tty alpine --image=alpine -- sh
}

You can now run the command ‘alpine_box’ to spin up an alpine linux pod in your kubernetes cluster. This is useful for troubleshooting issues from within the network.

Leave a Reply

Your email address will not be published. Required fields are marked *