What if you could run many websites on one server without messy setups or wasted resources?
Why Host-based routing in Kubernetes? - Purpose & Use Cases
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.
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.
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.
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;
}
}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
Host-based routing enables you to run multiple websites on a single Kubernetes cluster with simple, centralized traffic control.
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.
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.