Temporarily disable route in IngressRoute with custom status code (Traefik 2.4)


We're using Traefik 2.4 with Kubernetes 1.21.

We're making a breaking change to a service. We'd like to:

  1. Disable POSTs (writes) to a certain endpoint.
  2. Redeploy the k8s service; this brings up the new pod before bringing down the old one.
  3. Re-enable POSTs to that endpoint.

This way we don't have any downtime for reads to the service during this deployment.

I heard about the noop@internal service and tried it out:

# ingressroute.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute

  name: myservice
  - websecure
  # prevent POSTs to /my_path
  - kind: Rule
    match: Method(`POST`) && Path(`/api/my_path`)
    priority: 10000
    - name: noop@internal
      kind: TraefikService
  - kind: Rule
    match: PathPrefix(`/api`)
    - name: myservice
      port: 80

This successfully blocks POST /api/my_path from reaching myservice. However, this returns the status 418 I Am A Teapot. But for various reasons, we need to return 503 Service Unavailable instead.

Is there any kind of middleware or other built-in Traefik feature that can control this?

If one of these doesn't exist, we can probably create a very thin web service that always returns 503 and point the ingressroute rule at that service, but that seems a bit annoying.