Search⌘ K

Defining Rules per Host

Explore how to configure Kubernetes Ingress rules to serve different services on separate hosts by using host headers. Understand how to test host routing locally by modifying the DNS or request headers, enabling accurate HTTP traffic management for multiple domains.

Serving services in different hosts

So that’s nice! Now we can direct requests to the service we want based on the path we receive, such as / to nginx, /hello to hellok8s.

In practice, though, we usually will want to serve our services in different hosts. For example, we could want to serve nginx in http://nginx.example.com and hellok8s in http://hello.example.com.

Let’s see how we can change this Ingress to do that.

YAML
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-ingress
annotations:
# We are defining this annotation to prevent nginx
# from redirecting requests to `https` for now
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: nginx.local.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-svc
port:
number: 1234
- host: hello.local.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hellok8s-svc
port:
number: 4567

It’s pretty much the same manifest with two changes:

  • Instead of
...