From Docker to KubernetesStep 6 of 10: Inspect the Pod
All Labs

Inspect the Pod

Now that we have a Pod running in our Kubernetes Cluster, let’s see how we can interact with it, find out if the workload is running correctly, and how we can access the logs of the Pod.

Port Forwarding to access the workload

First, let’s try to find out if the HTTP workload is running correctly. By default, the Pod is not exposed to the outside world, so we cannot access it directly. However, we can use kubectl port-forward to forward a local port to the Pod’s port. This way, we can access the workload running in the Pod from our local machine. We will learn more about exposing workloads via Services in the following sections, but for now, let’s use port forwarding to access the workload.

To forward a local port to the Pod’s port, run the following command in your terminal:

kubectl port-forward pod/learning-tracker 8080:3000 -n learning-tracker

This command will forward the local port 8080 to the Pod’s port 3000 (the port the workloads listens to). You can now access it running in the Pod by opening your web browser and navigating to http://localhost:8080. You should see the Learning Tracker application running in your browser.

If you see the application running, congratulations! You have successfully accessed the workload running in the Pod. If you don’t see the application, make sure that the Pod is running and that you are using the correct port. When you are done inspecting the application, you can stop the port forwarding by pressing Ctrl+C in your terminal.

Inspect the Pod Logs

We changed the manifest to enable logging to the console, so let’s take a look at the logs of the Pod. You can do this by running the following command:

kubectl logs learning-tracker -n learning-tracker

This shows the logs of the learning-tracker Pod. You should see log messages from the application, indicating that it is running and ready to serve requests, such as:

❯ kubectl logs learning-tracker -n learning-tracker
info: Connected to SQLite database {"timestamp":"2025-08-17T18:31:12.279Z"}
info: Database schema created successfully {"timestamp":"2025-08-17T18:31:12.295Z"}
info: Database initialized successfully {"timestamp":"2025-08-17T18:31:12.296Z"}
info: Server running on port 3000 {"timestamp":"2025-08-17T18:31:12.297Z"}
info: Database type: sqlite {"timestamp":"2025-08-17T18:31:12.297Z"}
info: Logging to: console {"timestamp":"2025-08-17T18:31:12.297Z"}
Server running on http://localhost:3000
info: Added new learning item: Test {"timestamp":"2025-08-17T18:31:31.320Z"}

If you want to see the logs in real-time, you can use the -f flag to follow the logs.

Port-forwarding and inspecting logs are essential skills when working with Kubernetes, as they allow you to debug and troubleshoot your applications running in Pods.

In the log output before, you can see that our application is using SQLite as a database. As we might want to scale our application later, we will use a separate database instead of SQLite, therefore extend our application to use a MariaDB database. In the next section, we will create a Deployment for our workload and connect it to a MariaDB database and make it accessible.