This article provides solutions for troubleshooting pods, creating CronJobs, deploying pods, setting up Ingress resources, and inspecting logs in Kubernetes.
In this lesson, we walk through the solutions for Lightning Lab Two. This lab consists of several tasks designed to help you troubleshoot pods, update their configurations, create a CronJob, deploy a pod with custom parameters, set up an Ingress resource for virtual hosting routing, and inspect logs for warning messages.
Inspect the problematic pod—identified here as nginx1401 in the dev1401 namespace—by running:
Copy
Ask AI
kubectl describe pod nginx1401 -n dev1401
Examine the events section for clues. In this example, the events indicate that the readiness probe has failed, suggesting a misconfiguration. Next, extract the pod configuration to a YAML file for further inspection:
Copy
Ask AI
kubectl get pod nginx1401 -n dev1401 -o yaml > nginx1401.yaml
Review the configuration, which includes probe settings. A snippet from the YAML output might look like this:
Notice that although the readiness probe is set to check port 8080, other parts of the configuration might be expecting port 9080. To correct the inconsistency, update the configuration as follows:
The next task involves creating a CronJob called “dice” that runs every minute. This job leverages the kodekloud/throw-dice image, which randomly returns a number between one and six. A roll of six indicates success; any other result is a failure.Additional requirements for the CronJob include:
Running jobs non-parallel (in series).
Completing the task only once (completions: 1).
Using a backoff limit of 25.
Terminating the job if it runs longer than 20 seconds (using activeDeadlineSeconds: 20).
Setting the restart policy to Never.
Create the CronJob definition in a file called dice-job.yaml:
Task 4: Create an Ingress Resource for Virtual Hosting Routing
This task involves creating a single Ingress resource named ingress-vh-routing to handle virtual hosting routing for HTTP traffic. The configuration will route traffic as follows:
Requests to watch.ecom-store.com with the path /video will be directed to the video-service on port 8080.
Requests to apparels.ecom-store.com with the path /wear will be directed to the apparels-service on port 8080.
Create a file named ingress.yaml with the following content:
For the final task, inspect the logs of a pod in the default namespace that contains a container named log-x. Your goal is to redirect any warning messages to a file located at /opt/warnings.log on the control plane node.First, list the pods to identify the target pod:
Copy
Ask AI
kubectl get pod
Assuming the pod identified is dev-pod-dind-878516, execute the following command to filter and redirect warning messages:
Make sure you have the necessary permissions to write to /opt/ on the control plane node.
This concludes all tasks for Lightning Lab Two. Follow each step carefully to ensure proper configuration and successful task completion. Happy Kubernetes troubleshooting!For more Kubernetes tips and documentation, check out the Kubernetes Documentation.