I’m currently working on a setup where we combine AKS(Azure Kubernetes Service) with Azure Application Gateway for ingress. As always it’s quite an adventure especially in a fast moving ecosystem like Kubernetes.
In our setup we have one public IP address and domain. Our different applications are hosted as subsites.
An example:
- Root domain: www.ourdomainname.be
- App 1: www.ourdomainname.be/app1
- App 2: www.ourdomainname.be/app2
To do this we configure our ingress object like this:
2 things important to notice here:
- We added an ‘kubernetes.io/ingress.class’ annotation to specify that we want to use ‘azure/application-gateway’.
- We use the path to redirect the correct prefix to the correct service. e.g. traffic coming from app1 will be directed to service app1-api-service.
The problem with the setup above is that although our requests arrive perfectly to the correct service and pods, they arrive at the following relative URI /app1. Our pods expect to get the traffic at the root URI and the ASP.NET core routing doesn’t know how to handle the prefix. We could fix this at the Pod level but a better solution is to change this in the ingress and direct the traffic to the root of our pod.
To achieve this we have to add an extra annotation in our ingress object:
appgw.ingress.kubernetes.io/backend-path-prefix: "/"
The final ingress object looks like this: