<p>I have a workload, a service and an Nginx ingress controller routing traffic to the service. Everything is good as long as I have only one pod. Now when I scale up by setting the replicas to 2, the http errors returned by my API are transformed into an HTML page - hiding vital information I return with the error.</p>

<p>When my API returns:</p>

<pre><code>res.status(502).send('The error is THIS!');
</code></pre>

<p>What I see in the response is:</p>

<pre><code>&lt;html&gt;

&lt;head&gt;
    &lt;title&gt;502 Bad Gateway&lt;/title&gt;
&lt;/head&gt;

&lt;body bgcolor="white"&gt;
    &lt;center&gt;
        &lt;h1&gt;502 Bad Gateway&lt;/h1&gt;
    &lt;/center&gt;
    &lt;hr&gt;
    &lt;center&gt;nginx/1.11.3&lt;/center&gt;
&lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>How to bypass this custom error creation and receive my original error message?</p>

Charlie
<p>This is <a href="https://github.com/kubernetes/ingress-nginx/issues/1488" rel="nofollow noreferrer">by design</a>. If there is more than one backend (service endpoint) ingress-nginx will try the next backend when it receives a 502, 503 or 504 response status from the backend service. The custom error is produced when there are no more backends to try.</p>

<p>Setting the annotation <code>nginx.ingress.kubernetes.io/service-upstream: "true"</code> will change nginx's behaviour to point at one backend, the k8s cluster service ClusterIP. Normally nginx will manage all the services endpoints as backend servers.</p>

<p>Note that using this annotation moves the load balancing decisions to the Kubernetes clusters service routing domain rather than nginx's logic.</p>
