Kubernetes Ingress - 仅将子路径传递给后端而不是完整路径

Kubernetes Ingress - Pass only sub path to backend and not full path

我想要一个 Ingress,它将 host.com/abc/xyz 路由到 service/xyz。 我有以下配置,但它的路由 host.com/abc/xyzservice/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/* 路由到 service/* ? abc 不应包含在后端调用中。我也尝试过将 pathType 作为 ImplementationSpecific

如果您的服务是一个主机名。基于名称的虚拟主机支持将 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 流量,而无需基于名称的虚拟主机。

例如,以下 Ingress 将请求的流量路由到 myhost.net/abc/ 到 service1,service/* 到 service2

参考:https://kubernetes.io/docs/concepts/services-networking/ingress/

我按照此处所述使用后端路径前缀注释解决了这个问题 - https://github.com/Azure/application-gateway-kubernetes-ingress/blob/master/docs/annotations.md#backend-path-prefix