Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockererized Kong on windows giving "An invalid response was received from the upstream server"

Please help me as I am getting "An invalid response was received from the upstream server" error on getting the data from REST endpoint using Dockerized Kong.

REST service that I am trying to access using Kong is running on my localhost.

Kong Request to add API :

 curl -i -X POST \
--url http://localhost:8001/apis/ \
--data 'name=ping' \
--data 'upstream_url=http://localhost:8080/v1/employee/ping' \
--data 'hosts=localhost'

Forward request through Kong :

curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host:localhost'

Error that I am getting on forwarding the request through Kong:

[root@c1c865250782 etc]# curl -i -X GET --url http://localhost:8000/ --
header 'Host:localhost'
HTTP/1.1 502 Bad Gateway
Date: Fri, 29 Dec 2017 08:53:40 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/0.11.2

An invalid response was received from the upstream server

Please help me to solve this issue.

Thanks, Kamal

like image 240
Kamal Verma Avatar asked Dec 11 '22 08:12

Kamal Verma


1 Answers

I think you're running into the classic IP/Host issue you get when you start out with Docker. The key here is that you must pay attention to making your dockerized Kong be able to reach your localhost from inside the docker container. The issue here is (most likely) that Kong (inside docker) tries to access http://localhost:8080. But for Kong, that's the container it is running on itself.

To do this kind of testing, you will have to find the IP address of your local machine and add that as the upstream_url. Depending on where your machine is, in a home network, or in a corporate network, that will be something like 10.x.y.z, or 192.168.x.y. The command ifconfig (macOS) or ipconfig (Windows) will help you find that address. By using this IP instead, Kong will now be able to resolve your local computer's port 8080, instead of going to its own port 8080.

Please note that this means that you need to reconfigure the API in Kong each time you change IP address of your machine. Depending on whether it's a laptop, or if you use DHCP or such, this will be more or less often.


tl;dr: The upstream URL has to be an URL which enables Kong to resolve the target as seen from inside the Docker container.

like image 67
donmartin Avatar answered Apr 09 '23 08:04

donmartin