Course contentsShow
← Cloud and Infrastructure
Lesson 1224 of 2,98924. Kubernetes NetworkingFree lesson

Host-Based Routing

Configure Ingress to route traffic based on hostnames, enabling multiple domains on a single IP address.

Host-Based Routing

What you'll learn: How to configure a single Ingress resource to route incoming traffic to different services based on the hostname in the request.

What Is Host-Based Routing?

Host-based routing allows you to serve multiple applications or services using different domain names—all through a single IP address. Think of it like an apartment building's mailroom: one street address, but the mailroom sorts mail to different apartments based on the name on the envelope.

In Kubernetes, your Ingress controller listens on one IP address but routes traffic to different backend services depending on the Host header in the HTTP request (for example, app1.example.com vs. app2.example.com).

How It Works

When you define Ingress rules, you specify a host field. The Ingress controller examines each incoming request's hostname and matches it against these rules:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: multi-host-ingress
spec:
  rules:
  - host: shop.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: shop-service
            port:
              number: 80
  - host: blog.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: blog-service
            port:
              number: 80

In this example, requests to shop.example.com go to shop-service, while blog.example.com routes to blog-service—all through the same Ingress IP.

Why Use Host-Based Routing?

  • Cost efficiency: One load balancer IP instead of multiple
  • Simplified management: Single Ingress resource for multiple domains
  • Scalability: Add new domains without provisioning new infrastructure

Key Takeaway: Host-based routing in Ingress lets you serve multiple domain names from a single IP address by routing traffic based on the hostname, making multi-tenant or multi-application setups efficient and manageable.