suggest best way to do Path based routing using appgateway when multiple azure container is hosted as internal

210 views Asked by At

Here scenario is , we have app service needs to access the azure container apps hosted as internal, that can be accessesed with the vnet.

The app gateway routing works well if we have one container app and we have achieved using below link- single container solution

if suppose we have 2 container apps , if we have /api1/--> route to container1, if we have /api2/--> route to container2.

we tried to achieve the same but it gives can't able to reach site and the health probe shows success message for both backend pool with 302 cod and as a testing purpose we use http only

Any docx to follow up or expertise on this? if yes can any one suggest best way to test the same

1

There are 1 answers

2
ahmelsayed On

The best way to achieve this is by running those 2 container app as 'internal only' and creating a 3rd container app that is running a proxy of your chosing: e.g: nginx, envoy, caddy, yarp, apache, haproxy etc. and set whatever advanced routing configuration you want there. you can do pretty much whatever nginx or envoy or yarp can do at that moment. Your 'upstream' or 'target' is http://app1 and http://app2 (or whatever you named your apps)

Full example:

Here is an example nginx default.conf that routes /api1 -> app1 and /api2 -> app2

server {
    listen 8080;
    listen [::]:8080;
    server_name _;

    location /api1 {
        proxy_pass http://app1;
        proxy_http_version 1.1;
    }

    location /api2 {
        proxy_pass http://app2;
        proxy_http_version 1.1;
    }
    
    location / {
        return 404;
    }
}

You can either build your own nginx image using

FROM nginx

# assuming the above config is in a file called default.conf
COPY default.conf /etc/nginx/conf.d/

Or use the default nginx image and mount that as a file there. See this bicep template as an example https://github.com/ahmelsayed/bicep-templates/tree/main/apps/routers/nginx

It creates 3 apps, appv1 (internal) and appv2 (internal), and nginx (external), then mounts a very similar nginx config to the one above mapping

  • /version1 -> appv1
  • /version2 -> appv2
  • / -> 404

You can use the same approach with any other proxy