Skip to content

Latest commit

 

History

History
65 lines (44 loc) · 1.71 KB

4_logs.adoc

File metadata and controls

65 lines (44 loc) · 1.71 KB

Step 4: Logs

There are various "production-ready" ways to do log gathering and viewing across a Kubernetes/OpenShift cluster. Many folks like some flavor of ELK or EFK.

The focus here is on stuff a developer needs to get access to do help understand the behavior of their application running inside of a pod.

Make sure you are running 3 replicas (3 pods/instances of your application)

kubectl scale --replicas=3 deployment/myboot

and you can see them with kubectl get pods

$ kubectl get pods
NAME                      READY     STATUS    RESTARTS   AGE
myboot-68d666dd8d-cwtls   1/1       Running   0          3m
myboot-68d666dd8d-n874b   1/1       Running   0          3m
myboot-68d666dd8d-r8zpn   1/1       Running   0          11m

There is kubectl logs which is useful

$ kubectl logs myboot-68d666dd8d-r8zpn -f

or you can try stern, easily installable via homebrew on Mac https://github.com/wercker/stern

$ brew install stern

and use it like so

$ stern myboot

and in another terminal window, poll the various instances of the application

while true
do
  curl $(minikube ip):$(kubectl get service/myboot -o jsonpath="{.spec.ports[*].nodePort}")
  sleep .5;
done

and stern will let you see the logs across the 3 different pods.

Stern
Figure 1. stern output

This is more exciting when you might have 3 different microservices by the names are similiar enough to use stern.

stern also offers a --label selector

and if you are runnig Istio make sure to add the -c to specify your business logic container, instead of the side-car…​unless you wish to view the side-car’s logs :-)