How to set ingress-nginx custom errors

只谈情不闲聊 提交于 2021-01-29 13:49:10

问题


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:

  1. I have read the custom-errors document but there is no example of how to customize the default-backend.

  2. I do not understand the difference between ConfigMap and Annotation.

  3. How does ingress-nginx controller work in the first place.


回答1:


You can do it using two way :

  1. Adding annotation in ingress
  2. Change in ingress controller configmap (which is more like beckend)

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/



来源:https://stackoverflow.com/questions/57411698/how-to-set-ingress-nginx-custom-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!