Now that our Ingress controller is running, we are ready to deploy our Ingress resource. Create a new manifest file at ./manifests/backend/ingress.yaml with the following content:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: api.hobnob.social
http:
paths:
- backend:
serviceName: backend
servicePort: 8080
- host: docs.hobnob.social
http:
paths:
- backend:
serviceName: backend
servicePort: 8100
The important parts lies at .spec.rules. This is a list of rules that checks the request's host and path, and if it matches, proxies the request to a specified Service.
In our example, we are matching any requests for the domain api.hobnob.social to our backend service, on port 8080; likewise, we'll also forward requests for the host docs.hobnob.social to our backend Service, but on the 8100 port instead.
Now, deploy it with kubectl apply, and then wait for the address of the L4 load balancer to appear in the kubectl describe output:
$ kubectl apply -f ./manifest/backend/ingress.yaml
ingress.extensions "backend-ingress" created
$ kubectl describe ingress backend-ingress
Name: backend-ingress
Namespace: default
Address: 174.138.126.169
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
api.hobnob.social
backend:8080 (<none>)
docs.hobnob.social
backend:8100 (<none>)
Annotations:
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"nginx.ingress.kubernetes.io/rewrite-target":"/"},"name":"backend-ingress","namespace":"default"},"spec":{"rules":[{"host":"api.hobnob.social","http":{"paths":[{"backend":{"serviceName":"backend","servicePort":8080}}]}},{"host":"docs.hobnob.social","http":{"paths":[{"backend":{"serviceName":"backend","servicePort":8100}}]}}]}}
nginx.ingress.kubernetes.io/rewrite-target: /
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal UPDATE 2s nginx-ingress-controller Ingress default/backend-ingress
This means any requests with the hosts api.hobnob.social and docs.hobnob.social can now reach our distributed service!