Stern: Centralized logging for k8s

There is no doubt about the fact that kubernetes is already and progressing day by day as standard tool for container orchestration . We have to agree on the fact that kubernetes provides a lot of features and flexibility to deal with the container applications.

But there is one inconvenience about it ; like most of the other distributed systems it is hard to collect the logs of all containers running in different pods at a single place. One easy way to do it is via stern

Stern allows us to get logs from multiple kubernetes objects like deployment,services,jobs etc. Stern is an open-source project and we all are free to contribute to it as well.Let's see how it works.

Prerequisites: We should have a kubernetes cluster up and running.

[root@node1 stern]# kubectl get nodes
NAME                STATUS   ROLES    AGE   VERSION   Ready    master   55d   v1.18.3   Ready    <none>   55d   v1.18.3   Ready    <none>   55d   v1.18.3

Now we will login to the master node and install stern.

We can build it from the source code by cloning this git repo

But we are going to follow the easy way of just downloading the binary and executing it as command.

mv stern_linux_amd64 stern
chmod +x stern
mv stern  /usr/bin/

That's it , we are done with the installation. Let's see stern in action.

[root@node1 stern]# stern -n test  nginx -t --since 10m
+ nginx-deployment-d49467bd7-6pnfv › nginx
+ nginx-deployment-d49467bd7-jnb7f › nginx
+ nginx-deployment-d49467bd7-mmgbs › nginx
+ nginx-deployment-d49467bd7-vmh5m › nginx
+ nginx-deployment-d49467bd7-kxlcc › nginx
+ nginx-deployment-d49467bd7-44tx7 › nginx
+ nginx-deployment-d49467bd7-2n8dp › nginx
+ nginx-deployment-d49467bd7-xhc5h › nginx
+ nginx-deployment-d49467bd7-tb6g9 › nginx
+ nginx-deployment-d49467bd7-vwbxh › nginx

[root@node1 stern]# stern metrics-server --namespace kube-system

So this was a short introduction about stern. Similar tools available are:




Filebeat + Logstash

Have more idea ? Please share in comment section...

288 views0 comments

Subscribe Form

©2020 by Linux Advise