简体   繁体   English

允许 Azure 应用程序网关路由 AKS 中的所有子路径

[英]Allow Azure Application Gateway to route all sub paths in AKS

I have AKS configured with Azure Application Gateway as my ingress.我将 AKS 配置为 Azure 应用程序网关作为我的入口。

I am trying to deploy a .net core Angular app to a path within the cluster.我正在尝试将 .net 核心 Angular 应用程序部署到集群中的路径。 I would like to access the app on http://<cluster ip>/app1 .我想访问http://<cluster ip>/app1上的应用程序。

My kube.netes deployment (including ingress settings) is as follows:我的 kube.netes 部署(包括入口设置)如下:

apiVersion: v1
kind: Pod
metadata:
  name: web-app-1
  labels:
    app: web-app-1
spec:
  containers:
  - image: "xxx.azurecr.io/web-app-1:latest"
    name: web-app-1
    imagePullPolicy: Always
    ports:
    - containerPort: 80
      protocol: TCP

---

apiVersion: v1
kind: Service
metadata:
  name: web-app-1
spec:
  selector:
    app: web-app-1
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-app-1
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
  - http:
      paths:
      - path: /app1
        backend:
          serviceName: web-app-1
          servicePort: 80

In the Angular app itself, I have left <base href="/" /> in index.html .在 Angular 应用本身中,我将<base href="/" />留在了index.html中。 However, I have amended the build to now be ng build --base-href /app1/"但是,我已将构建修改为ng build --base-href /app1/"


Issue问题

When this is deployed and I browse to http://<cluster ip>/app1 then it loads the index.html file.部署后,我浏览到http://<cluster ip>/app1 ,然后它会加载 index.html 文件。 However it returns a 404 for all the additional scripts eg 404 on http://<cluster ip>/app1/main-es2015.9ae13a2658e759db61f5.js但是,它会为所有其他脚本返回 404,例如 404 on http://<cluster ip>/app1/main-es2015.9ae13a2658e759db61f5.js

The issue could be with how I've configured Angular, but browsing to http://<cluster ip>/app1/index.html returns a 404 when I know it can be accessed just using /app1/ .问题可能出在我如何配置 Angular,但浏览到http://<cluster ip>/app1/index.html返回 404 当我知道它可以仅使用/app1/访问时。

I believe the issue is that Application Gateway is not routing requests properly for anything after /app1/ .我认为问题在于应用程序网关没有为/app1/之后的任何内容正确路由请求。 How can I get it to allow sub routes through (ie the scripts)?我怎样才能让它允许子路由通过(即脚本)?

Thanks谢谢

Got this working now.现在开始工作了。 If I looked at the 404 response headers it says it was from kestrel, so was hitting the dotnet core api, so it needs configuring there.如果我查看 404 响应标头,它说它来自 kestrel,因此正在访问 dotnet 核心 api,因此需要在那里进行配置。 All the changes I made were:我所做的所有更改是:

Client:客户:

  • Leave the base href as / eg将基本 href 保留为/ eg
  • Add the base href to the build argument eg ng build --base-href /app1/"将 base href 添加到 build 参数中,例如 ng build --base-href /app1/"
  • In Configure of Startup.cs , add app.UsePathBase("/app1");Startup.cs Configure中,添加app.UsePathBase("/app1"); I do this in the else of env.IsDevelopment() .我在env.IsDevelopment()else中这样做。

Application Gateway:应用网关:

  • Change the path for the rules to - path: /app1* .将规则的路径更改为- path: /app1* I didn't have the asterisk so wasn't routing all subsequent routes.我没有星号,所以没有路由所有后续路线。

You could also do something like this你也可以这样做

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: appgw-ingress
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    appgw.ingress.kubernetes.io/backend-path-prefix: "/"
spec:
  rules:
  - http:
      paths:
      - path: /api/*
    ....

Where you are updating the routing prefix form "/" to "/api/*".将路由前缀形式“/”更新为“/api/*”的位置。 Specifically this annotation特别是这个注释

appgw.ingress.kubernetes.io/backend-path-prefix: "/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有应用程序网关入口 controller 配置的 AKS - AKS with Application gateway ingress controller configuration API 网关在所有路径上失败 flask - API Gateway failing on all paths with flask AKS ISTIO 网关不可访问 - AKS ISTIO Gateway is not accessiable Azure 流量管理器给出 SSL 错误,而 App 网关 URL 在 AKS 上使用 Azure App 网关入口 controller 时工作 - Azure Traffic manager gives SSL error while App gateway URL works while using Azure App gateway ingress controller on AKS 重写应用程序网关规则 azure - Rewrite rule on application gateway azure 使用 Azure 应用程序网关阻止所有 http/https 流量的 WAF 规则 - WAF Rule to block all http/https traffic using Azure Application gateway 使用自定义 su.net 为 AKS 群集启用应用程序网关入口 Controller (AGIC) 加载项 - Enable the Application Gateway Ingress Controller (AGIC) add-on for an AKS cluster using custom subnet 通过 Bicep 模板使用应用程序网关入口加载项创建 AKS 集群 - Create AKS Cluster with Application Gateway Ingress Add-on via Bicep Template Azure 事件网格主题的应用程序网关后端池 - Azure Application Gateway backendpool to Event Grid Topic Azure 应用程序网关文件上传限制 - Azure Application Gateway file upload limits
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM