0
0
Kubernetesdevops~3 mins

Why Host-based routing in Kubernetes? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could run many websites on one server without messy setups or wasted resources?

The Scenario

Imagine you run a website that serves different content for different domains, like shop.example.com and blog.example.com. Without host-based routing, you must manually configure separate servers or IP addresses for each domain.

The Problem

This manual setup is slow and error-prone. You have to manage multiple servers or IPs, update DNS records, and handle traffic routing yourself. It's easy to misroute users or waste resources by running many servers.

The Solution

Host-based routing lets you use one server or load balancer to direct traffic based on the website address users enter. Kubernetes Ingress can automatically send requests to the right service depending on the host name, simplifying management and saving resources.

Before vs After
Before
server {
  listen 80;
  server_name shop.example.com;
  location / {
    proxy_pass http://shop-service;
  }
}

server {
  listen 80;
  server_name blog.example.com;
  location / {
    proxy_pass http://blog-service;
  }
}
After
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-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
What It Enables

Host-based routing enables you to run multiple websites on a single Kubernetes cluster with simple, centralized traffic control.

Real Life Example

A company hosts its marketing site, customer portal, and blog on the same Kubernetes cluster. Using host-based routing, all traffic is routed correctly without needing separate servers or IPs.

Key Takeaways

Manual routing requires multiple servers and complex setup.

Host-based routing directs traffic by domain name automatically.

Kubernetes Ingress makes managing multiple sites easy and efficient.