<p>I use the kubernetes ingress-nginx controller and a set custom errors on GKE but I have some problems.</p>

<p>Goal:
If a 50x error occurs in <code>something-web-app</code>, I'll return the HTTP status code 200 and JSON <code>{"status":200, "message":"ok"}</code></p>

<p>Problems:</p>

<ol>
<li><p>I have read the <a href="https://kubernetes.github.io/ingress-nginx/examples/customization/custom-errors/" rel="nofollow noreferrer">custom-errors document</a> but there is no example of how to customize the <code>default-backend</code>.</p></li>
<li><p>I do not understand the difference between ConfigMap and Annotation.</p></li>
<li><p>How does ingress-nginx controller work in the first place.</p></li>
</ol>

<p>You can do it using two way :</p>
<ol>
<li>Adding annotation in ingress</li>
<li>Change in ingress controller configmap (which is more like beckend)</li>
</ol>
<p><strong>1</strong>. Try adding this annotation to kubernetes ingress :</p>
<blockquote>
<p>nginx.ingress.kubernetes.io/default-backend: nginx-errors-svc</p>
<p>nginx.ingress.kubernetes.io/custom-http-errors: 404,503</p>
<p>nginx.ingress.kubernetes.io/default-backend: error-pages</p>
</blockquote>
<p>If that doesn't work add this along with two :</p>
<pre><code>nginx.ingress.kubernetes.io/server-snippet: |
      location @custom_503 {
        return 404;
      }
      error_page 503 @custom_503;
</code></pre>
<p><strong>2.</strong> Configmap editing</p>
<p>You can apply this config map to ingress controller</p>
<pre><code>apiVersion: v1
kind: ConfigMap
name: nginx-configuration-ext
data:
  custom-http-errors: 502,503,504
  proxy-next-upstream-tries: &quot;2&quot;
  server-tokens: &quot;false&quot;
</code></pre>
<p>You can also refer this blog : <a href="https://habr.com/ru/company/flant/blog/445596/" rel="nofollow noreferrer">https://habr.com/ru/company/flant/blog/445596/</a></p>
