Reputation: 23798
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.
When my API returns:
res.status(502).send('The error is THIS!');
What I see in the response is:
<html>
<head>
<title>502 Bad Gateway</title>
</head>
<body bgcolor="white">
<center>
<h1>502 Bad Gateway</h1>
</center>
<hr>
<center>nginx/1.11.3</center>
</body>
</html>
How to bypass this custom error creation and receive my original error message?
Upvotes: 2
Views: 1233
Reputation: 74720
This is by design. 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.
Setting the annotation nginx.ingress.kubernetes.io/service-upstream: "true"
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.
Note that using this annotation moves the load balancing decisions to the Kubernetes clusters service routing domain rather than nginx's logic.
Upvotes: 2