我想要一个入口,路由host.com/abc/xyz到服务/xyz.我有以下配置,但它的路由host.com/abc/xyz到服务/abc/xyz.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
appgw.ingress.kubernetes.io/connection-draining: "true"
appgw.ingress.kubernetes.io/connection-draining-timeout: "30"
appgw.ingress.kubernetes.io/request-timeout: "300"
appgw.ingress.kubernetes.io/health-probe-status-codes: "200-399, 401"
kubernetes.io/ingress.class: azure/application-gateway
generation: 1
name: serviceAingress
namespace: pantry-services
spec:
rules:
- host: myhost.net
http:
paths:
- backend:
serviceName: serviceA
servicePort: 8083
path: /abc/*
pathType: Prefix
- backend:
serviceName: serviceA
servicePort: 8083
path: /abc
pathType: Prefix
如何将myhost.net/abc/*路由到服务/* ?不应该将ABC包含在后端调用中。我也尝试过pathType作为ImplementationSpecific
我使用这里描述的后端路径前缀注释解决了这个问题- https://github.com/Azure/application-gateway-kubernetes-ingress/blob/master/docs/annotations.md#backend-path-prefix
如果您的服务主机名。基于名称的虚拟主机支持将HTTP流量路由到同一IP地址的多个主机名。建议您使用以下方式。yaml代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: myhost.net
http:
paths:
- pathType: Prefix
path: "abc/*"
backend:
service:
name: service1
port:
number: 80
- host: service
http:
paths:
- pathType: Prefix
path: "/*"
backend:
service:
name: service2
port:
number: 80
如果您创建的Ingress资源没有在规则中定义任何主机,那么任何到您的Ingress控制器的IP地址的web流量都可以匹配,而不需要基于名称的虚拟主机。
例如,以下入口将请求myhost.net/abc/的流量路由到service1,请求service/*的流量路由到service2
参考:https://kubernetes.io/docs/concepts/services-networking/ingress/