4

I have deployed the standard aspnet app from Microsoft, from the following YAML:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: microservicesapp
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: aspnetapp
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: aspnetapp
spec:
  selector:
    app: aspnetapp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
  name: aspnetapp
  labels:
    app: aspnetapp
spec:
  containers:
  - image: "mcr.microsoft.com/dotnet/core/samples:aspnetapp"
    name: aspnetapp-image
    ports:
    - containerPort: 80
      protocol: TCP

Everything works fine when I call the public IP associated with my AGW resourced. However, I want to configure the path of the ingress, so that it is /test. Like so:

  - http:
      paths:
      - path: /test
        backend:
          serviceName: aspnetapp
          servicePort: 80

When I attempt to call the endpoint from outside the cluster, this results in 502 Bad Gateway. The Controller logs after deployment of the resources in the above YAML:

I0918 17:25:16.798265       1 health_probes.go:55] Created default HTTP probe defaultprobe-Http
I0918 17:25:16.798272       1 health_probes.go:56] Created default HTTPS probe defaultprobe-Http
I0918 17:25:16.798279       1 ingress_rules.go:148] Found backend:default/aspnetapp
I0918 17:25:16.798405       1 health_probes.go:70] Created probe pb-default-aspnetapp-80-microservicesapp for ingress default/microservicesapp at service default/aspnetapp
I0918 17:25:16.798613       1 backendhttpsettings.go:190] Created backend http settings bp-default-aspnetapp-80-80-microservicesapp for ingress default/microservicesapp and service default/aspnetapp
I0918 17:25:16.798671       1 backendaddresspools.go:37] Created default backend pool defaultaddresspool
I0918 17:25:16.798698       1 backendaddresspools.go:48] Created backend pool pool-default-aspnetapp-80-bp-80 for service default/aspnetapp
I0918 17:25:16.798709       1 frontend_listeners.go:121] Processing Rules for Ingress: default/microservicesapp
I0918 17:25:16.798828       1 requestroutingrules.go:349] Attached pool pool-default-aspnetapp-80-bp-80 and http setting bp-default-aspnetapp-80-80-microservicesapp to path rule: pr-default-microservicesapp-0
I0918 17:25:16.798861       1 requestroutingrules.go:107] Bound path-based rule: rr-e1903c8aa3446b7b3207aec6d6ecba8a to listener: fl-e1903c8aa3446b7b3207aec6d6ecba8a ([    ], 80) and url path map url-e1903c8aa3446b7b3207aec6d6ecba8a
I0918 17:25:16.808144       1 mutate_app_gateway.go:174] Generated config:
...

What is the correct way to set a path, like /test, so that all traffic to that path, is directed to the aspnetapp service?

Mike Hawkins
  • 2,144
  • 5
  • 24
  • 42
  • you have used a microsoft managed image here, how do you know there is a path `/test` in the application. Have you confirmed from somewhere that the application will respond successfully when sent a request with path `/test`. If yes can you post that link here. – vishal Sep 28 '20 at 12:02
  • usually if you give path /test and link a service behind it should forward request when we enter appgw ip/test to that service or pod behind it right I dont understand why you are asking whether application configured /test. – DevOpsGeek Sep 28 '20 at 12:33
  • /test is at application gateway level right? can you please refer application gateway ing image from below doc and let me know if am saying something wrong. https://learn.microsoft.com/en-us/azure/application-gateway/create-url-route-portal – DevOpsGeek Sep 28 '20 at 12:39
  • @vishal.k any thoughts? – DevOpsGeek Sep 29 '20 at 14:49
  • @DevOpsGeek You need to have better understanding on the role of application gateway and the meaning of 502 error here. You have configured `/test` to a said backendpool in the appgw. Now appgw will forward request to the correct backend but if your application doesn't have any response for such a path, then it wont send back any response which will result in 502. As I already told below, build your own simple nginx image with a html page for `/test` and try the same case, you will understand what is happening here. – vishal Sep 29 '20 at 15:07
  • @vishal.k Okay vishal I understood your point that i should have /test in backend thats why im getting 502, but i changed /test to /app ( /app is the folder in the backend where all the aspnet app files exists) /app also throwing 502 error. I would request you to kindly reproduce once from your end and look into it once. Thanks for understanding!!!! – DevOpsGeek Sep 30 '20 at 12:37
  • I Urge you to recreate from your end and look at it once – DevOpsGeek Sep 30 '20 at 12:48
  • Does this answer your question? [Ingress is not working for application gateway ingress controller (AGIC) add-on of AKS](https://stackoverflow.com/questions/67573856/ingress-is-not-working-for-application-gateway-ingress-controller-agic-add-on) – Sreyas Sep 09 '21 at 05:57

1 Answers1

6

Add path prefix annotation appgw.ingress.kubernetes.io/backend-path-prefix: "/" in the ingress resource.The annotation tells application gateway to create an HTTP setting which will have a path prefix override for the path /test to /

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: microservicesapp
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-path-prefix: "/"
spec:
  rules:
  - http:
      paths:
      - path: /test
        backend:
          serviceName: aspnetapp
          servicePort: 80
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • 1
    I did. Same result. – Mike Hawkins Sep 18 '20 at 17:12
  • Check logs of azure app gateway ingress controller pods – Arghya Sadhu Sep 18 '20 at 17:13
  • I updated OP with the logs. I also tried the things you suggested in my other post, but didn't work. – Mike Hawkins Sep 18 '20 at 17:28
  • @ArghyaSadhu Same issue with me only works for / if you add multiple paths like /front etc for multiple services it didnt work though! – DevOpsGeek Sep 21 '20 at 09:39
  • When i add multiple paths like / /app1, /app2 html pages are loading without css and config files – DevOpsGeek Sep 21 '20 at 13:18
  • 2
    @DevOpsGeek It is loading without HTML and CSS because the application is configured in such a way to respond successfully only when request come from `/`. This is just how the application is designed. No problem here with AGIC. To confirm this yourself, Build a custom docker image with nginx that serves request at path `/test`. Then the ingress configuration posted in the question will work. – vishal Sep 28 '20 at 12:08
  • 1
    It works this way but will fail for other subpaths; this very same app has a link 'Privacy'; with your ingress setup, if you click on the link 'Privacy', it gets you 502. Similar ingress works well if you have nginx with rewrite-target annotation - like path: /test(|/*) and rewrite-target: /$1 even the css would load in case of webapp; it is just that AGIC is in very early stage. – Venkatesh Laguduva Nov 19 '20 at 13:33