azure - 当多个 Azure 容器作为内部托管时,建议使用 appgateway 进行基于路径的路由的最佳方法

标签 azure azure-container-service azure-container-apps

这里的场景是,我们的应用程序服务需要访问作为内部托管的 Azure 容器应用程序,可以通过 vnet 访问这些应用程序。

如果我们有一个容器应用程序并且我们已经使用以下链接实现了应用程序网关路由 - single container solution

假设我们有 2 个容器应用程序,如果我们有/api1/--> 路由到容器 1,如果我们有/api2/--> 路由到容器2。

我们尝试实现相同的目标,但它无法访问站点,并且运行状况探测显示后端池的成功消息(带有 302 cod),并且作为测试目的,我们仅使用 http

有任何需要跟进的文档或这方面的专业知识吗?如果是的话,任何人都可以建议测试相同的最佳方法

最佳答案

实现这一目标的最佳方法是将这 2 个容器应用程序作为“仅限内部”运行,并创建一个运行您选择的代理的第三个容器应用程序:例如:nginx、envoy、caddy、yarp、apache、haproxy 等.并在那里设置您想要的任何高级路由配置。你几乎可以做 nginx 或 envoy 或 yarp 此刻能做的任何事情。您的“上游”或“目标”是 http://app1http://app2 (或您为应用命名的任何名称)

完整示例:

这是一个示例 nginx default.conf,它路由/api1 -> app1 和/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;
    }
}

您可以使用构建自己的 nginx 镜像

FROM nginx

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

或者使用默认的 nginx 镜像并将其作为文件安装在那里。请参阅此二头肌模板作为示例 https://github.com/ahmelsayed/bicep-templates/tree/main/apps/routers/nginx

它创建 3 个应用程序,appv1(内部)和 appv2(内部)以及 nginx(外部),然后安装与上面映射非常相似的 nginx 配置

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

您可以对任何其他代理使用相同的方法

关于azure - 当多个 Azure 容器作为内部托管时,建议使用 appgateway 进行基于路径的路由的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76961209/

相关文章:

Azure DocumentDB 和 Spring Boot 冲突

azure - Windows Azure Web 部署加速器的存储事务分析器

node.js - 如何使用 Azure api 启动容器实例?

azure - 如何为容器化 Web 应用程序配置自定义域?

azure - 该容器服务处于失败状态

azure - 是否可以在 Azure 容器应用程序中创建一次性(运行至完成)作业?

Azure 策略 'modify' 效果与修复

azure - 从 Microsoft.Azure.ServiceBus 迁移到 Azure.Messaging.ServiceBus

azure - Dapr 重试的指数退避 (AzureServiceBus)

azure - 创建 Azure 应用服务 yaml 文件后无法编辑配置