Custom ingress error pages without intercepts

I've just spent ages trying to work out exactly this problem, and there doesn't seem to be any documented solution out there. So here's what eventually worked for me.

What we really want to do is to not intercept any errors, but instead to change nginx's error page, ideally serving them from our default backend just as we would any intercepted errors.

So you can set up a new location to handle that by adding the following to your ingress controller's ConfigMap:

 server-snippet: |
    location @503 {
      proxy_set_header X-Code 503;
      proxy_set_header X-Format "text/html";
      proxy_pass http://default-backend.ingress-nginx;
    }

(assuming you have your default backend deployed with a service called default-backend in a namespace called ingress-nginx).

Then on the Ingress you want this behaviour you can add an annotation to redirect 503 errors to our new route:

 annotations:
   nginx.ingress.kubernetes.io/configuration-snippet: |
     error_page 503 = @503;

Now the 503 error that would have been served from nginx directly is now served from your default backend, without intercepting any "real" 503s that could be returned from your app's pods when they are eventually up and running.