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?

8
  • 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, 2020 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, 2020 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. learn.microsoft.com/en-us/azure/application-gateway/…
    – DevOpsGeek
    Sep 28, 2020 at 12:39
  • @vishal.k any thoughts?
    – DevOpsGeek
    Sep 29, 2020 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, 2020 at 15:07

1 Answer 1

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
7
  • 1
    I did. Same result. Sep 18, 2020 at 17:12
  • Check logs of azure app gateway ingress controller pods Sep 18, 2020 at 17:13
  • I updated OP with the logs. I also tried the things you suggested in my other post, but didn't work. Sep 18, 2020 at 17:28
  • 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, 2020 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. Nov 19, 2020 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.