Hello,
I'd like to define custom error-pages with traefik ingress in kubernetes. Although the kubernets-services get 400 or 503 back when I curl them with their ClusterIP, the traefik-ingress does not send my error page, which actually is just a default nginx site.
My config:
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.class: traefik-internal
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/preserve-host: "false"
traefik.frontend.passHostHeader: "false"
traefik.ingress.kubernetes.io/error-pages: |-
foo:
status:
- "400"
- "503"
backend: all-errors
query: /
labels:
app.kubernetes.io/instance: nextcloud-staging
app.kubernetes.io/name: nextcloud
namespace: nextcloud-staging
spec:
rules:
- host: all-errors
http:
paths:
- backend:
serviceName: nginx
servicePort: 80
path: /
- host: nextcloud.example.org
http:
paths:
- backend:
serviceName: app-service
servicePort: 80
path: /
tls:
- hosts:
- nextcloud.example.org
secretName: nextcloud.example.org-certificate
Just to see that my error-site works correctly:
# kubectl -n nextcloud-staging get svc nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.97.208.190 <none> 80:30086/TCP 63m
# curl 10.97.208.190
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Actually, my nextcloud-app has problem, so the error-code is 400:
# kubectl -n nextcloud-staging get svc app-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app-service ClusterIP 10.99.178.76 <none> 80/TCP 24m
# curl -Sf 10.99.178.76
curl: (22) The requested URL returned error: 400 Bad Request
But the ingress does not switch to the custom error site:
# curl -fS https://nextcloud.example.org
curl: (22) The requested URL returned error: 400 Bad Request
When I stop my app (with scaling to replica=0), the service is not available anymore, of course:
# kubectl -n nextcloud-staging get svc app-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app-service ClusterIP 10.99.178.76 <none> 80/TCP 26m
# curl -Sf 10.99.178.76
curl: (7) Failed to connect to 10.99.178.76 port 80: Connection refused
But the ingress does not switch to the error site again:
# curl -fS https://nextcloud.example.org
curl: (22) The requested URL returned error: 503 Service Unavailable
I am looking forward to your help.
Thanks in advance!