ingress-nginx: Default Backend Annotation Incompatible with custom-http-errors

Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT, i think

NGINX Ingress controller version: 0.22.0 Kubernetes version (use kubectl version): 1.12.4 What happened: If you specify a default-backend override in an ingress resource while also including custom-http-errors, I believe the proxy-intercept-errors are not respecting the annotation default-backend.

What you expected to happen: That you can use custom-http-errors to proxy_intercept_errors to your custom default backend of your choosing

How to reproduce it (as minimally and precisely as possible): The yaml below has the service scaled to 0. This means the service WILL 503.
Using the yaml files referenced below, deploy it to a kube cluster (and adjust the ingress route to meet your cluster needs). Deploy it once with JUST the default-backend annotation. You will get your default backend 503 error as defined by this image. quay.io/kubernetes-ingress-controller/custom-error-pages-amd64:0.3. Now uncomment the #nginx.ingress.kubernetes.io/custom-http-errors: 404,503` annotation and it will no longer goto your default backend.

# ECHOSERVER EXAMPLE APP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: echo-svc
spec:
  replicas: 0
  selector:
    matchLabels:
      app: echo-svc
  template:
    metadata:
      labels:
        app: echo-svc
    spec:
      containers:
      - name: echo-svc
        image: gcr.io/kubernetes-e2e-test-images/echoserver:2.1
        ports:
        - containerPort: 8080
        env:
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
---
apiVersion: v1
kind: Service
metadata:
  name: echo-svc
  labels:
    app: echo-svc
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
    
    name: http
  selector:
    app: echo-svc
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/default-backend: nginx-errors-svc # This is referencing the SAME NAMESPACE that this resource is in
   #nginx.ingress.kubernetes.io/custom-http-errors: 404,503
  name: echo-app-ingress
spec:
  rules:
  - host: echo.domain.com
    http:
      paths:
      - backend:
          serviceName: echo-svc
          servicePort: http
        path: /
---
# ECHOSERVER CUSTOM DEFAULT BACKEND (ATTEMPTING TO OVERRIDE THE DEFAULT BACKEND DEFINED IN THE CONTROLLER INSTALLATION)
apiVersion: v1
kind: Service
metadata:
  name: nginx-errors-svc
  labels:
    app.kubernetes.io/name: nginx-errors
    app.kubernetes.io/part-of: ingress-nginx
spec:
  selector:
    app.kubernetes.io/name: nginx-errors
    app.kubernetes.io/part-of: ingress-nginx
  ports:
  - port: 80
    targetPort: 8080
    name: http
---
apiVersion: apps/v1beta2
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  name: nginx-errors
  labels:
    app.kubernetes.io/name: nginx-errors
    app.kubernetes.io/part-of: ingress-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: nginx-errors
      app.kubernetes.io/part-of: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: nginx-errors
        app.kubernetes.io/part-of: ingress-nginx
    spec:
      containers:
      - name: nginx-error-server
        image: quay.io/kubernetes-ingress-controller/custom-error-pages-amd64:0.3
        ports:
        - containerPort: 8080

Anything else we need to know:

Since the default-backend annotation code only adds an override for 503 - there isn’t a real way to have custom-http-errors and a per-namespace default backend override with this bug

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

If you delete the ingress controller pod (forcing it to restart), does the new pod come up with the correct config?

Yes, it does. But in a few seconds controller decides to reload config and comes up with upstream-default-backend. Cut from logs (diff config):

I0918 08:51:21.035055       6 nginx.go:709] NGINX configuration diff:
--- /etc/nginx/nginx.conf       2019-09-18 08:51:17.745151892 +0000
+++ /tmp/new-nginx-cfg383168094 2019-09-18 08:51:21.029196557 +0000
@@ -1,5 +1,5 @@
 
-# Configuration checksum: 3635007615741738390
+# Configuration checksum: 10146389228757143632
 
 # setup custom paths that do not require root access
 pid /tmp/nginx.pid;
@@ -2883,7 +2883,7 @@
                
                set $proxy_upstream_name "-";
                
-               location @custom_custom-default-backend-dev-qa-site-db_404 {
+               location @custom_upstream-default-backend_404 {
                        internal;
                        
                        proxy_intercept_errors off;
@@ -2898,7 +2898,7 @@
                        proxy_set_header       X-Request-ID       $req_id;
                        proxy_set_header       Host               $best_http_host;
                        
-                       set $proxy_upstream_name custom-default-backend-dev-qa-site-db;
+                       set $proxy_upstream_name upstream-default-backend;
                        
                        rewrite                (.*) / break;
                        
@@ -3113,7 +3113,7 @@
                        # Custom error pages per ingress
                        proxy_intercept_errors on;
                        
-                       error_page 404 = @custom_custom-default-backend-dev-qa-site-db_404;
+                       error_page 404 = @custom_upstream-default-backend_404;
                        
                        proxy_pass http://upstream_balancer;
                        
I0918 08:51:21.058431       6 controller.go:149] Backend successfully reloaded.
I0918 08:51:21.059451       6 controller.go:172] Dynamic reconfiguration succeeded.