#devops #kubernetes #logging #tools
When debugging your applications on Kubernetes, getting the right information from the different pods isn't trivial. Especially if you are using deployments which use multiple replicas, checking which pod is the one you need is tricky.
Before Kubernetes, it was easy to SSH into a server and use the
tail command to view the logfile(s). You can still do this, but it's quite cumbersome.
First, you need to figure out the correct name of the pod using
1$ kubectl get pods 2NAME READY STATUS RESTARTS AGE 3babette-6f7bc7ff8c-pmkzv 1/1 Running 0 25h 4download-server-8d674d785-ppbfz 1/1 Running 0 4d21h 5job-server-5db7f9468c-wcncp 1/1 Running 0 26h
Once you have the name, you need to use
kubectl to dump the logfile:
1$ kubectl log babette-6f7bc7ff8c-pmkzv 2<log content goes here>
log command is really limited and doesn't e.g. offer the option to follow the logfile.
In these cases, a utility such as
kail (the abbreviation of Kubernetes tail) is there to help you.
If you are on a mac, you can install it as follows:
1$ brew tap boz/repo 2$ brew install boz/repo/kail
For other platforms, you can just download the binaries.
You can then use it to monitor multiple pods as once in the same way as you use
tail. I prefer to add proper labels to my pods so that I can select on them. If you label all your pods for the
staging environment with a label
staging, you can follow the logs of all these pods with this simple command:
1$ kail -l environment=staging
It will prepend each logline with the name of the pod as soon as it comes in.
You can find all the options and the source code for
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.