...

/

Defining Rules per Host

Defining Rules per Host

Learn how we can serve our services in different hosts.

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.

Press + to interact
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 ...

Access this course and 1400+ top-rated courses and projects.