<p>I need to set a custom error in traefik ingress on kubernetes so that when there is no endpoint or when the status is "404", or "[500-600]" it redirects to another error service or another custom error message I used the annotation as it's in the documentation in the ingress file as this (Note: this a helm template output of passing the annotation as a yaml in the values.yaml file)</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
  namespace: "default"
  annotations:
      external-dns.alpha.kubernetes.io/target: "domain.com"
      kubernetes.io/ingress.class: "traefik"
      traefik.ingress.kubernetes.io/error-pages: "map[/:map[backend:hello-world status:[502 503]]]"
spec:
  rules:
  - host: frontend.domain.com
    http:
      paths:
      - backend:
          serviceName: frontend
          servicePort: 3000
        path: /
</code></pre>

yara mohamed
<p>The answer by ldez is correct, but there are a few caveats:</p>

<ul>
<li>First off, these annotations only work for traefik >= 1.6.x (earlier versions may support error pages, but not for the kubernetes backend)</li>
<li>Second, the traefik backend <strong>must</strong> be configured through kubernetes. You cannot create a backend in a config file and use it with kubernetes, at least not in traefik 1.6.x </li>
</ul>

<p>Here's how the complete thing looks like. <code>foo</code> is just a name, as explained in the other answer, and can be anything:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
  namespace: "default"
  annotations:
      external-dns.alpha.kubernetes.io/target: "domain.com"
      kubernetes.io/ingress.class: "traefik"
      traefik.ingress.kubernetes.io/error-pages: |-
        foo:
          status:
          - "404"
          - "500"
          # See below on where "error-pages" comes from
          backend: error-pages
          query: "/{{status}}.html"
spec:
  rules:
   # This creates an ingress on an non-existing host name,
   # which binds to a service. As part of this a traefik
   # backend "error-pages" will be created, which is the one
   # we use above
   - host: error-pages
     http:
       paths:
       - backend:
         serviceName: error-pages-service
         servicePort: https
- host: frontend.domain.com
    http:
    # The configuration for your "real" Ingress goes here

# This is the service to back the ingress defined above
# Note that you can use anything for this, including an internal app
# Also: If you use https, the cert on the other side has to be valid
---
kind: Service
apiVersion: v1
metadata:
  name: error-pages-service
  namespace: default
spec:
  ports:
  - name: https
    port: 443
  type: ExternalName
  externalName: my-awesome-errors.mydomain.test
</code></pre>

<p>If you use this configuration, and your app sends a 404, then <code>https://my-awesome-errors.mydomain.test/404.html</code> would be shown as the error page.</p>
