gpt4 book ai didi

kubernetes - 应用程序网关入口 Controller 仅适用于根路径/

转载 作者:行者123 更新时间:2023-12-02 11:38:33 29 4
gpt4 key购买 nike

我已经从以下 YAML 部署了来自 Microsoft 的标准 aspnet 应用程序:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: microservicesapp
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: aspnetapp
servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
name: aspnetapp
spec:
selector:
app: aspnetapp
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
name: aspnetapp
labels:
app: aspnetapp
spec:
containers:
- image: "mcr.microsoft.com/dotnet/core/samples:aspnetapp"
name: aspnetapp-image
ports:
- containerPort: 80
protocol: TCP
当我调用与我的 AGW 资源关联的公共(public) IP 时,一切正常。但是,我想配置入口的路径,使其为 /test .像这样:
  - http:
paths:
- path: /test
backend:
serviceName: aspnetapp
servicePort: 80
当我尝试从集群外部调用端点时,这会导致 502 Bad Gateway。上述 YAML 中资源部署后的 Controller 日志:
I0918 17:25:16.798265       1 health_probes.go:55] Created default HTTP probe defaultprobe-Http
I0918 17:25:16.798272 1 health_probes.go:56] Created default HTTPS probe defaultprobe-Http
I0918 17:25:16.798279 1 ingress_rules.go:148] Found backend:default/aspnetapp
I0918 17:25:16.798405 1 health_probes.go:70] Created probe pb-default-aspnetapp-80-microservicesapp for ingress default/microservicesapp at service default/aspnetapp
I0918 17:25:16.798613 1 backendhttpsettings.go:190] Created backend http settings bp-default-aspnetapp-80-80-microservicesapp for ingress default/microservicesapp and service default/aspnetapp
I0918 17:25:16.798671 1 backendaddresspools.go:37] Created default backend pool defaultaddresspool
I0918 17:25:16.798698 1 backendaddresspools.go:48] Created backend pool pool-default-aspnetapp-80-bp-80 for service default/aspnetapp
I0918 17:25:16.798709 1 frontend_listeners.go:121] Processing Rules for Ingress: default/microservicesapp
I0918 17:25:16.798828 1 requestroutingrules.go:349] Attached pool pool-default-aspnetapp-80-bp-80 and http setting bp-default-aspnetapp-80-80-microservicesapp to path rule: pr-default-microservicesapp-0
I0918 17:25:16.798861 1 requestroutingrules.go:107] Bound path-based rule: rr-e1903c8aa3446b7b3207aec6d6ecba8a to listener: fl-e1903c8aa3446b7b3207aec6d6ecba8a ([ ], 80) and url path map url-e1903c8aa3446b7b3207aec6d6ecba8a
I0918 17:25:16.808144 1 mutate_app_gateway.go:174] Generated config:
...
设置路径的正确方法是什么,例如 /test ,以便该路径的所有流量都定向到 aspnetapp 服务?

最佳答案

添加路径前缀注释appgw.ingress.kubernetes.io/backend-path-prefix: "/"在入口资源中。注解告诉应用程序网关创建一个 HTTP 设置,该设置将为路径 /test 提供路径前缀覆盖至/

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: microservicesapp
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/backend-path-prefix: "/"
spec:
rules:
- http:
paths:
- path: /test
backend:
serviceName: aspnetapp
servicePort: 80

关于kubernetes - 应用程序网关入口 Controller 仅适用于根路径/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63959961/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com