Logging
1. Introduction
useful for debugging
to see what's going on inside the containers
2. Creating a pod
- that writes to stdout and stderr
hadoop@k8s-00:~$ kubectl create -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/logging/pod.yaml
pod "logme" created
3. To view the 5 most recent logs use
hadoop@k8s-00:~$ kubectl logs --tail=5 logme -c gen
Mon Jun 18 05:42:04 UTC 2018
Mon Jun 18 05:42:05 UTC 2018
Mon Jun 18 05:42:05 UTC 2018
Mon Jun 18 05:42:06 UTC 2018
Mon Jun 18 05:42:06 UTC 2018
where --tail=n specifies the n recent logs
- --since=n secs option, which is used to see the log details since the last n seconds
hadoop@k8s-00:~$ kubectl logs -f --since=10s logme -c gen
Mon Jun 18 05:45:59 UTC 2018
Mon Jun 18 05:45:59 UTC 2018
Mon Jun 18 05:46:00 UTC 2018
Mon Jun 18 05:46:00 UTC 2018
Mon Jun 18 05:46:01 UTC 2018
Mon Jun 18 05:46:01 UTC 2018
Mon Jun 18 05:46:02 UTC 2018
to view the logs on the containers that have already completed their tasks, we can do follows
create a pod oneshot
hadoop@k8s-00:~$ kubectl create -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/logging/oneshotpod.yaml
pod "oneshot" created
- we can see that the pod has completed it's task
hadoop@k8s-00:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
badpod 0/1 CrashLoopBackOff 15 39m
hc 1/1 Running 0 45m
logme 1/1 Running 0 8m
oneshot 0/1 Completed 3 51s
ready 1/1 Running 0 33m
- still we can get the logs of the completed tasks as follows
hadoop@k8s-00:~$ kubectl logs -p oneshot -c gen
9
8
7
6
5
4
3
2
1