Paths in an Ingress resource route requests based on the URL path specified in the incoming HTTP request. When a request is made to a specific URL, the Ingress controller examines the defined rules in the Ingress manifest to determine how to route that request. Here’s how the routing process works:
Routing Process
-
Incoming Request: When a client makes an HTTP request to a specific URL (e.g.,
http://example.com/service1), the request is sent to the Ingress controller. -
Ingress Controller: The Ingress controller is responsible for managing the Ingress resources and handling incoming traffic. It checks the rules defined in the Ingress manifest.
-
Matching Rules: The Ingress controller looks for a matching rule based on the host and path:
- Host: The controller first checks if the request's host matches any of the defined hosts in the Ingress rules.
- Path: If the host matches, it then checks the path of the request against the defined paths in the rules. The path matching can be done using different strategies, such as:
- Exact Match: The path must match exactly.
- Prefix Match: The path must start with the specified prefix (e.g.,
/service1matches/service1and/service1/another-path).
-
Routing to Backend: Once a matching rule is found, the Ingress controller routes the request to the specified backend service defined in the rule. The backend service will handle the request and return a response.
Example
Using the previous example:
rules:
- host: example.com
http:
paths:
- path: /service1
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
- path: /service2
pathType: Prefix
backend:
service:
name: service2
port:
number: 80
- A request to
http://example.com/service1will be routed toservice1. - A request to
http://example.com/service2will be routed toservice2. - A request to
http://example.com/service1/extrawill also be routed toservice1due to the prefix match.
Summary
Paths in an Ingress resource allow you to define how incoming requests are routed to different services based on the URL structure. This enables you to manage multiple services under a single domain efficiently.
