In this lesson, you will learn how to direct incoming HTTP traffic to specific backend services by inspecting the contents of the request itself, rather than just the connection metadata.
Beyond the Network Layer
While basic Kubernetes Services operate at Layer 4 (Transport layer), effectively routing traffic often requires understanding the "intent" of the request. Layer 7 routing allows your Ingress controller to make intelligent decisions based on the application layer protocols. By analyzing HTTP headers, URL paths, or the requested hostname, you can steer traffic with surgical precision—a critical requirement for modern, microservice-based GitOps architectures.
Routing Logic in Practice
Imagine you have a single entry point for your platform, but you need to send all requests to /api/v1/payments to your payment-service while routing everything else to your frontend-service. An Ingress resource allows you to define these rules declaratively:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
spec:
rules:
- host: api.example.com
http:
paths:
- path: /payments
pathType: Prefix
backend:
service:
name: payment-service
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
By leveraging host matching, you can host multiple applications on one load balancer, and by using path matching, you can decompose a monolithic URL structure into independent backend services. You can even route based on headers (e.g., sending users with a specific X-Beta-User: true header to a canary version of a service), which is an essential building block for the progressive delivery strategies we’ve explored in previous lessons.
Because this configuration is stored in your Git repository, your GitOps controller ensures that these routing rules remain consistent across environments, preventing "configuration drift" where traffic might accidentally be misdirected during a deployment.
Key Takeaway: Layer 7 routing empowers you to decouple your public-facing URL architecture from your internal microservice deployment topology by inspecting HTTP request properties.