Skip to main content
In this lesson, we troubleshoot a sample application that exposes web services through an Ingress. The application consists of three pods—Kanye, Techie, and Useless—each paired with its corresponding service. These services deliver distinct types of quotes: Kanye quotes, tech-related quotes, and random humorous quotes.

Examining the Kubernetes Environment

Below is an example of our Kubernetes environment displaying the available pods:
The image shows a terminal interface displaying Kubernetes services with details like name, type, cluster IP, ports, and age. The interface includes commands and shortcuts for managing the services.
All services are hosted behind an Ingress controller. The Ingress resource routes incoming requests based on the URL path. For instance, requests to /techy are directed to the Techie service—similarly for the Kanye and Useless services. This configuration utilizes the Nginx Ingress Controller.

Ingress Configuration Overview

The following excerpt illustrates the Ingress configuration that implements load balancing and reverse proxying behavior:
This setup directs HTTP requests to their respective backend services based on the request path.

Verifying Ingress Behavior

First, retrieve the Ingress IP address with:
Curling the Ingress IP without specifying a path returns an HTML 404 error accompanied by an image:
When using a specific service path (e.g., /techy), the response is:
Using verbose curl output confirms the 404 status:
Similarly, requests to /kanye yield a 404 error:
The Ingress Controller logs indicate that the requests are reaching the controller, but the backend services return a 404 because they are not configured to handle the prefixed path.

Diagnosing the Issue with Port-Forwarding

To isolate the problem, we use kubectl port-forward to bypass the Ingress and directly access the Techie service:
The direct request returns a valid Techie quote:
This confirms that the application is functioning as expected and that the issue lies in the path handling between the Ingress and the backend services. When the Ingress passes the original path (e.g., /kanye), the backend applications do not recognize the prefix, resulting in a 404 response.

Implementing the Rewrite Target

The solution involves using the Nginx Ingress Controller’s Rewrite Target annotation. This annotation modifies the URL path before it reaches your backend service. In other words, it strips the service-specific prefix so that the service receives requests on its root path. Refer to the Nginx Ingress Controller documentation on rewrite annotations for additional details.
The image shows a webpage from the Ingress-Nginx Controller documentation, specifically focusing on rewrite annotations. It includes sections on prerequisites and deployment, with a table listing annotation names, descriptions, and values.
A common pattern uses a capture group in a regular expression to pass only the desired part of the path to the backend. Consider this example configuration:
In this example, the following rewrite behaviors occur when running the configuration with kubectl create -f -:
  • rewrite.bar.com/something rewrites to rewrite.bar.com/
  • rewrite.bar.com/something/ rewrites to rewrite.bar.com/
  • rewrite.bar.com/something/new rewrites to rewrite.bar.com/new
Back in our setup, we can apply a simple rewrite target to strip the service-specific path:
After applying this updated Ingress configuration, testing with curl shows that the services now receive the expected, rewritten requests. For example:
Other services can be verified similarly:
This demonstrates the importance of both correctly defining an Ingress resource and understanding how request path rewrites impact backend service behavior.

Reviewing the Generated Nginx Configuration

To further troubleshoot, it is useful to examine the Nginx configuration generated by the Ingress Controller. This configuration defines the load balancer behavior, including the evaluation order for location blocks and timeout settings.
Additional configuration snippets such as timeout settings can be defined by annotations or directly in the configuration file:
A sample grep on the Nginx configuration might reveal:
Reviewing the effective Nginx configuration is critical to ensure that your timeout and proxy settings match your expectations. Adjust these values as necessary to optimize your application’s performance.

Conclusion

This troubleshooting session has demonstrated not only how to define an Ingress resource but also the importance of proper URL path rewriting. By implementing the Nginx Ingress Controller’s rewrite-target annotation, we ensure that backend services receive requests in the expected format—eliminating 404 errors caused by unexpected path prefixes. Mastering the nuances of Ingress configurations is essential for managing traffic routing and resolving production issues effectively. Happy troubleshooting!

Watch Video

Practice Lab