Score:0

How to force Nginx Ingress controller to respond HTTP 426 to deprecated routes

mo flag

I have the following ingress for my namespace on Kubernetes with paths /api/1.0/ redirecting to my old-service and the rest redirecting to the new. Before deprecating & deleting my old-service I would like Nginx to respond with an HTTP 426 redirect error code only on the /api/1.0/ paths.

How can I do this ?

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
in flag
Hi Victor R welcome to S.F. All `Ingress` objects are unioned together, so create a 2nd `Ingress` with just that `path:` and then use [`configuration-snippet:`](https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet) to do whatever crazy nginx-y things you want when that path matches
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.