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

Allow Azure Application Gateway to route all sub paths in AKS

我将 AKS 配置为 Azure 应用程序网关作为我的入口。

我正在尝试将 .net 核心 Angular 应用程序部署到集群中的路径。我想在 http://<cluster ip>/app1.

上访问该应用程序

我的kubernetes部署(包括ingress设置)如下:

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

在 Angular 应用程序本身中,我在 index.html 中留下了 <base href="/" />。但是,我已将构建修改为 ng build --base-href /app1/"


问题

部署后,我浏览到 http://<cluster ip>/app1,然后它会加载 index.html 文件。然而,它 returns 一个 404 用于所有额外的脚本,例如http://<cluster ip>/app1/main-es2015.9ae13a2658e759db61f5.js

上的 404

问题可能出在我配置 Angular 的方式上,但浏览到 http://<cluster ip>/app1/index.html returns 404 时我知道只需使用 /app1/ 即可访问它.

我认为问题在于应用程序网关在 /app1/ 之后没有正确路由任何请求。我怎样才能让它允许子路由通过(即脚本)?

谢谢

现在可以正常使用了。如果我查看 404 响应 headers,它说它来自 kestrel,所以它击中了 dotnet 核心 api,所以它需要在那里配置。我所做的所有更改是:

客户:

  • 将基本 href 保留为 /,例如
  • 将基本 href 添加到构建参数中,例如ng build --base-href /app1/"
  • Startup.csConfigure中,添加app.UsePathBase("/app1");我在env.IsDevelopment()else中这样做。

应用程序网关:

  • 将规则的路径更改为 - path: /app1*。我没有星号,所以没有路由所有后续路由。