0
0
Kubernetesdevops~15 mins

kubectl logs for debugging in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Using kubectl logs for Debugging Kubernetes Pods
📖 Scenario: You are managing a Kubernetes cluster where a web application is running inside a pod. Sometimes the application crashes or behaves unexpectedly. To find out what is wrong, you need to check the logs of the pod.This project will guide you step-by-step to use kubectl logs command to fetch logs from a pod for debugging.
🎯 Goal: Learn how to use kubectl logs to view logs of a Kubernetes pod to help debug issues.
📋 What You'll Learn
Have access to a Kubernetes cluster with kubectl configured
Know the exact pod name to fetch logs from
Understand basic kubectl commands
💡 Why This Matters
🌍 Real World
Developers and operators use kubectl logs to check what is happening inside containers running in Kubernetes. Logs help find errors and understand application behavior.
💼 Career
Knowing how to use kubectl logs is essential for Kubernetes administrators, DevOps engineers, and developers working with containerized applications.
Progress0 / 4 steps
1
Identify the pod name
Create a variable called pod_name and set it to the exact pod name webapp-pod-12345.
Kubernetes
Need a hint?

The pod name is a string. Use single quotes around it.

2
Set the container name
Create a variable called container_name and set it to the container name webapp-container inside the pod.
Kubernetes
Need a hint?

The container name is also a string. Use single quotes.

3
Write the kubectl logs command
Create a variable called logs_command that stores the exact command string to get logs from the pod using kubectl logs with the pod name and container name variables. The command should be: kubectl logs webapp-pod-12345 -c webapp-container.
Kubernetes
Need a hint?

Use an f-string to insert the variables into the command string.

4
Print the logs command
Write a print statement to display the logs_command variable.
Kubernetes
Need a hint?

Use print(logs_command) to show the command.