Skip to main content

Monitor and Output Logs to a File in Kubernetes

Hands-On Lab

 

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

You can troubleshoot broken pods quickly using the kubectl logs command. You can manipulate the output and save it to a file in order to capture important data. In this hands-on lab, you will be presented with a broken pod, and you must collect the logs and save them to a file in order to better understand the issue.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Monitor and Output Logs to a File in Kubernetes

In this hands-on lab, we have been presented with a broken pod, and we must collect the logs and save them to a file in order to better understand the issue.

Log in to the Kube Master server using the credentials on the lab page (either in your local terminal, using the Instant Terminal feature, or using the public IP), and work through the objectives listed.

Identify the problematic pod in your cluster.

Use the following command to view all the pods in your cluster:

kubectl get pods --all-namespaces

Collect the logs from the pod.

Use the following command to collect the logs from the broken pod:

kubectl logs <pod_name> -n <namespace_name>

Output the logs to a file.

Use the following command to output the logs to a file:

kubectl logs <pod_name> -n <namespace_name> > broken-pod.log

Conclusion

Congratulations on completing this lab!