如何強制 Nginx Ingress 控制器回應 HTTP 426 已棄用的路由

如何強制 Nginx Ingress 控制器回應 HTTP 426 已棄用的路由

我在 Kubernetes 上的命名空間有以下入口和路徑/api/1.0/重定向到我的舊服務,其餘的重定向到新服務。在棄用和刪除我的舊服務之前,我希望 Nginx 僅在以下位置回應 HTTP 426 重定向錯誤代碼:/api/1.0/路徑。

我怎樣才能做到這一點 ?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: xxx-ingress
  namespace: xxx-ingress
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-next-upstream: "error timeout http_502 non_idempotent"
    nginx.ingress.kubernetes.io/proxy-pass-headers: "Content-Length"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - api.xxx.com
    - www.xxxcom
    secretName: xxx-ingress-tls
  rules:
    - host: api.xxx.com
      http:
        paths:
          - path: /api/1.0/users/password/reset/token
            pathType: ImplementationSpecific
            backend:
              service:
                name: old-service
                port:
                  number: 80
          - path: /api/1.0/users/login
            pathType: ImplementationSpecific
            backend:
              service:
                name: old-service
                port:
                  number: 80
          - path: /api/1.0/users/request_migration_sync
            pathType: ImplementationSpecific
            backend:
              service:
                name: old-service
                port:
                  number: 80
          - path: /api/1.0/users/migrate
            pathType: ImplementationSpecific
            backend:
              service:
                name: old-service
                port:
                  number: 80
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: new-service
                port:
                  number: 80
    - host: www.xxx.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: new-service
                port:
                  number: 80

相關內容