[英]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/"
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:客户:
/
eg/
egConfigure
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:应用网关:
- 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.