Basic Ingress Rules and Paths
You'll learn: How to create Ingress resources that route traffic to different Services based on URL paths.
What Are Ingress Rules and Paths?
Now that you have an Ingress Controller installed, you need to define rules that tell it where to send incoming HTTP requests. Think of an Ingress resource like a receptionist at a building entrance: when visitors arrive asking for different departments, the receptionist checks their request and directs them to the right office.
An Ingress rule defines how to match incoming requests (by hostname or path) and which Service should handle them. Paths let you route different URL endpoints to different backend Services—all through a single external entry point.
Basic Path-Based Routing
Here's a simple Ingress with path-based rules:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 8080
- path: /web
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
In this example:
- Requests to
myapp.example.com/api→ routed toapi-service - Requests to
myapp.example.com/web→ routed toweb-service
The pathType: Prefix means any URL starting with that path matches (e.g., /api/users, /api/orders).
Path Types
- Prefix: Matches if the URL path begins with the specified path
- Exact: Matches only if the URL path is exactly the specified path
Key Takeaway: Ingress rules with path-based routing let you direct different URL paths to different backend Services, enabling sophisticated HTTP routing through a single external IP address.