This is the most common issue that every DevOps guy faces, while working on Kubernetes. One day suddenly you will find that one of the pod you are working is in bad state. And you dont know what went wrong. So as a DevOps engineer you need to be aware of how to view logs of running pod or crashed pod.
First you need to know which pod you want see logs for, to do that
Get the pods
kubectl get pods -A To list all pods irrespective of namespace
kubectl get pods -n <namespace> To get list of pods from a specific namespace
kubectl get pods To get list of pods from default namespace
[devopsvm@dev ~]$ kubectl get pods
NAMESPACE NAME READY STATUS RESTARTS AGE
default jenkins-master-wed66fcfc-kasdas 1/1 Running 1 18d
default nfs-client-provisioner-6756-75vc5q 1/1 Running 0 86d
Get logs of running pods
If pod running in default namespace
kubectl log jenkins-master-wed66fcfc-kasdas
if pod running in a different namespace
kubectl log jenkins-master-wed66fcfc-kasdas -n <namespace>
To see logs in realtime (use -f option)
-f option gives you logs in real time on your screen, to exit press CTRL+C or CTRL+Z
kubectl logs -f jenkins-master-wed66fcfc-kasdas
-p or --previous option give option to see logs of a pod which got restarted or crashed. In above case you see jenkins is restarted 1 time..so if you want to see like why it got restarted, use either of the option.
[devopsvm@dev ~]$ kubectl get pods
NAMESPACE NAME READY STATUS RESTARTS AGE
default jenkins-master-wed66fcfc-kasdas 2/2 Running 1 18d
No comments:
Post a Comment