Kubectl Hacks - Be productive- 3 mins
This post talks about extending kubectl with few of the plugins that have been useful to me in day to day debugging/maintaining things on k8s.
Note: I am using zsh, so some of them are ohmyzsh plugins
Lets go through them!
This plugins provides aliases for common kubectl commands. You can get complete list of aliases here — kubectl-aliases
- k for
kubectl— The kubectl command
- kgp for
kubectl get pods— List all pods in ps output format
- kgswide for
kgs -o wide— After listing all services, output in plain-text format with any additional information
kubectx + kubens — Power tools for kubectl (+ fzf )
If you work with multiple clusters or namespaces then this tool is a blessing.
- kubectx — helps you switch between clusters back and forth
- kubens — helps you switch between namespaces back and forth
- Setting context:
kubectl config get-contextsand
kubectl config use-context <context-name>
- Setting namespace:
kubectl get namespacesand
kubectl config set-context --current --namespace=<namespace>
Along with fzf — A command-line fuzzy finder, it gives an interactive menu to select the context/namespace as shown above in gif
When dealing with multiple contexts and namespaces, it becomes confusing to determine what is the current context/namespace you are working on.
You can check for the current context/namespace using
kubectl config current-context and
kubectl config view to determine current namespace. This is fine when you are not dealing with multiple contexts and don’t have to switch frequently.
But if you do, this can be a saviour when doing certain operations or debugging production incidents where you have to change contexts frequently. Any wrong step and you can end up doing destructive operations on wrong cluster.
kube-ps1 or zsh-kubectl-prompt adds context and namespace upfront in your prompt, so that you can be sure of cluster and namespace you are working on.
A tiny bash script to tail multiple pod logs in single stream. It is simply
kubectl logs -f but for multiple pods.
You can do regex matching on pods, view specific container logs or can simply give multiple pods. This tool comes in handy when debugging issues with our applications. kubetail in action
Kubespy tools help in observing Kubernetes resources in real time. This is useful when you want to keep a track of resources on various actions you perform.
checkout kubespy in action — kubespy observing deployment resource status changes
K9s provides a terminal UI to interact with your Kubernetes clusters. The aim of this project is to make it easier to navigate, observe and manage your applications in the wild. K9s continually watches Kubernetes for changes and offers subsequent commands to interact with your observed resources.
Let me know if these were useful to you as well. If you have any suggestions do comment!