K8s – Question17

Use context: kubectl config use-context k8s-c1-H

In Namespace project-tiger create a Pod named tigers-reunite of image httpd:2.4.41-alpine with labels pod=container and container=pod. Find out on which node the Pod is scheduled. Ssh into that node and find the containerd container belonging to that Pod.

Using command crictl:

  1. Write the ID of the container and the info.runtimeType into /opt/course/17/pod-container.txt
  2. Write the logs of the container into /opt/course/17/pod-container.log

Capturing Container Information and Logs in Kubernetes

Kubernetes provides powerful tools for managing and inspecting containers running within Pods. In this guide, we’ll walk through the process of creating a Pod, identifying its associated container, capturing runtime details, and retrieving logs directly from the container. These steps are crucial for debugging and monitoring your applications in a Kubernetes environment.

Step 1: Creating the Pod

First, we’ll create a new Pod in the project-tiger namespace. This Pod will run an HTTPD server using the httpd:2.4.41-alpine image and will have specific labels applied:

This command creates a Pod named tigers-reunite with the specified image and labels, which you can use later for querying or organizing resources.

Step 2: Identifying the Node Where the Pod is Running

Next, we need to determine which node the Pod is scheduled on. You can do this by running the following command:

For a more targeted approach, you can also use the following command to get just the node name:

This will return the name of the node where the Pod is running, which is essential for the next steps.

Step 3: Accessing the Node and Inspecting the Container

Now that we know the node where the Pod is running, we’ll SSH into that node to inspect the container:

Once logged in, find the container ID associated with the tigers-reunite Pod:

This command will output details about the running container, including its ID, which we’ll use for further inspection. For example:

Next, inspect the container to determine the runtime type:

The output should look something like this:

Step 4: Capturing Container Information

Now that we have the container ID and runtime type, let’s store this information in a file on the main terminal:

This file records the container ID and its runtime type for future reference.

Step 5: Retrieving Container Logs

Finally, let’s capture the logs from the container and save them into a log file. You can do this by running the following command:

This command redirects both standard output and standard error to a log file. The log file might look something like this:

These logs provide valuable insights into the operation of your container, helping you debug and monitor the HTTPD server.

Conclusion

In this guide, we’ve demonstrated how to create a Kubernetes Pod, identify and inspect its container, and retrieve logs directly from the container. These skills are essential for effective troubleshooting and monitoring in Kubernetes, ensuring that your applications run smoothly in your cluster.

Leave a Reply

Your email address will not be published. Required fields are marked *