Skip to main content
In this lesson, we troubleshoot an accessibility issue with our NeonCat application. We deploy both a service and a deployment on Kubernetes, then use kubectl port-forward to diagnose why the application is unreachable. This guide walks through inspecting resources, establishing port forwarding, identifying configuration mismatches, and resolving the issue.

Inspecting Kubernetes Resources

Start by confirming that your pod, service, and deployment are running correctly:
Notice that the service nyancat-service is configured to expose port 80. This is the port that you plan to forward local traffic to.

Establishing Port Forwarding

Next, set up port forwarding by choosing a local port (for example, 3000) and forwarding it to your service’s port 80:
Open a separate terminal and verify connectivity by running:
If you encounter an error like:
it indicates a misconfiguration in your resource definitions.

Diagnosing the Port Configuration Mismatch

The detailed output from the port-forward command might reveal an error such as:
This error indicates that the port-forward command is attempting to map local port 3000 to port 8000 on the pod rather than port 80.
The service is configured to listen on port 80 but forwards traffic to targetPort 8000 on the pod. However, the deployment’s container is actually listening on port 80.

Service Definition

Below is the current service configuration:

Deployment Configuration

And here is the deployment configuration:
The table below summarizes the configuration discrepancy:

Resolving the Issue

To correct the problem, update the service configuration so that its targetPort matches the container’s listening port. Change the service’s targetPort from 8000 to 80. You can edit the service with the following command:
After updating, run the port-forward command again to map local port 3000 to the service’s port 80:

Verifying the Fix

Test the application again by curling localhost on port 3000 or by opening http://localhost:3000 in your browser. A successful response might look similar to this:
Now, traffic flows correctly from local port 3000 to service port 80 and finally to the container’s port 80.
Ensuring that the service’s targetPort matches the container’s listening port removes unnecessary translation layers and prevents connection issues.

By aligning your port configurations, you eliminate the extra hop (from port 80 to 8000) that caused the connection refusal. This exercise emphasizes the importance of consistent port settings across your Kubernetes resources for reliable application accessibility.

Watch Video