These easily accessible Command Line Tools are fantastic for debugging and utilizing Kubernetes (k8s) cloud resources from the command line.
Who is this for?
This guide is coming from the perspective of someone trying to operate, develop and debug applications that are hosted via k8s. As someone who does this on a daily basis, I have come to appreciate a few wonderful tools that make the process much easier.
The usefulness of each tool scales nicely with the level of infrastructure present within your organization. Those that are without multiple namespaces and/or contexts might not be served as well, but might still benefit from the knowledge of their existence.
We would like to reduce
$ kubectl config set-context <insert-context-here> --namespace=<insert-namespace-name-here>
$ kubectl get pods | <tool-of-choice-to-extract-pod-list>
$ kubectl log -f <pod-1> & kubectl log -f <pod-2> & ...kubectl log -f <pod-N>
down to something much more manageable, with low cognitive performance.
Aside: Context vs namespaces.
Getting Started
Prerequisites:
-
A Cloud Service Provider + k8s.
- The target for most of this guide, if you are not actively utilizing some form of k8s, this will not be useful for you.
- Kubectl.
Installation
Usage
Switch k8s contexts.
$ kubectx <context_name>
Switch k8s namespace.
$ kubens <namespace_name>
Tail pods.
stern <pod_name>
Often we'll find ourselves trying to debug a specific container within our pods. This might be due to a split in services across the pod. We can do
$ stern --container <container-name> <pod-name>
Voilà, we have significantly reduced our cognitive load and made switching contexts in our shell of choice much easier. We could take this a step further and alias out these commands, but I'll leave that to the reader. As they stand these are suitable for much quicker debugging sessions.
Aside: Making life even easier with Kubectl-aliases
Thank you for reading, and have a wonderful day 😊 💕
Top comments (0)