I use the kubernetes ingress-nginx controller and a set custom errors on GKE but I have some problems.
Goal: If a 50x error occurs in something-web-app
, I'll return the HTTP status code 200 and JSON {"status":200, "message":"ok"}
Problems:
I have read the custom-errors document but there is no example of how to customize the default-backend
.
I do not understand the difference between ConfigMap and Annotation.
How does ingress-nginx controller work in the first place.
You can do it using two way :
1. Try adding this annotation to kubernetes ingress :
nginx.ingress.kubernetes.io/default-backend: nginx-errors-svc
nginx.ingress.kubernetes.io/custom-http-errors: 404,503
nginx.ingress.kubernetes.io/default-backend: error-pages
If that doesn't work add this along with two :
nginx.ingress.kubernetes.io/server-snippet: |
location @custom_503 {
return 404;
}
error_page 503 @custom_503;
2. Configmap editing
You can apply this config map to ingress controller
apiVersion: v1
kind: ConfigMap
name: nginx-configuration-ext
data:
custom-http-errors: 502,503,504
proxy-next-upstream-tries: "2"
server-tokens: "false"
You can also refer this blog : https://habr.com/ru/company/flant/blog/445596/