Defining a fallback service for Kubernetes ingress

Viewed 2084

Is it possible to have a fallback service for Kubernetes ingresses in the event that none of the normal pods are live/ready? In other words, how would you go about presenting a friendly "website down" page to visitors if all pods crashed or went down somehow?

Right now, a page appears that says "default backend - 404" if that happens.

Here's what we tried, to no avail:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
spec:
  backend:
    serviceName: website-down-service
    servicePort: 80
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: example-service
              servicePort: 80

For reference, we're testing locally with Minikube and deploying to the cloud on Google's Container Engine.

2 Answers

If using Nginx then default backend annotation should do the trick, sample:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-name
  namespace: your-namespace
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/default-backend: fallback-backend
spec:
   <your spec here>
Related