0

I have setup Kong API gateway following the documentation here. With the curl command below, I can confirm that Kong is up and responding via localhost.

curl -i http://localhost:8001/services
    
    HTTP/1.1 200 OK
    Date: Thu, 13 May 2021 15:39:32 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Access-Control-Allow-Origin: http://localhost:8002
    X-Kong-Admin-Request-ID: xeUkwshQPRXA5T9bPQmxsmPcspJCGU2L
    vary: Origin
    Access-Control-Allow-Credentials: true
    Content-Length: 23
    X-Kong-Admin-Latency: 5
    Server: kong/2.3.3.2-enterprise-edition

My question is, for production, how to configure Kong to respond to DNS/URL?

I have set up a DNS record on AWS Route 53 to point traffic at the IP of this server where Kong is deployed. With a standalone application - a Node/Express app for exmaple, I would set up a reverse proxy ie NGINX to route requests received to the server from a URL onwards to the app. However, as Kong is the API gateway, that wouldn't be appropriate.

To summarise;

Kuyashii
  • 360
  • 1
  • 4
  • 21
  • Kong is listening on a port, then kong can route based on domain. What do you call listening on a host ? – Ôrel May 13 '21 at 18:30
  • I'm not sure I follow. Let's say I have a service behind Kong eg /serviceA/pathA - how would I call this this from an external client? – Kuyashii May 13 '21 at 18:51
  • `upstream service` in kong terminology https://docs.konghq.com/gateway-oss/2.4.x/proxy/#terminology – Ôrel May 13 '21 at 20:14

1 Answers1

1

If you want to route based on the host, this is a classic feature.

First create a service (your node application):

service create

Then create a route:

create route

route details

Then you can test the route is matched

curl -i --header 'kong-debug: 1' http://my-gateway-url.com:8000

HTTP/1.1 502 Bad Gateway
Date: Fri, 14 May 2021 08:11:54 GMT
Content-Type: text/plain; charset=utf-8
Connection: keep-alive
Kong-Route-Id: 9f5584d7-4ac5-4720-a90c-f809c47faf8d
Kong-Route-Name: my_gw
Kong-Service-Id: 77443f69-80f4-49ea-b910-77eebdeb9385
Kong-Service-Name: node_app
Server: kong/2.0.3
Content-Length: 58

compared to

curl -i --header 'kong-debug: 1' 0.0.0.0:8000
HTTP/1.1 404 Not Found
Date: Thu, 13 May 2021 20:11:23 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 48

{"message":"no Route matched with those values"}

Another thing to check is which port you cant to expose 80 or 8000, and check that the route is open on your security level (Security group on AWS for example).

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • Your approach is setting Host headers etc According to this gist, it is possible to add DNS so that the client needs only do `curl my-gateway-url.com` to proxy the request through to the node app, which what I am trying to achieve: https://gist.github.com/montanaflynn/a3a9336384d42188a45e – Kuyashii May 13 '21 at 20:35
  • See the last comment on the page linked above – Kuyashii May 13 '21 at 20:35
  • Plus, in your example you are calling the API gateway at localhost 0.0.0.0:8000 - I just want to know how to call the API gateway from a client external to localhost – Kuyashii May 13 '21 at 21:25
  • I didn't set the dns and I have deployed in local to do the screen shot. The goal is to show the routing per hostname. Updated with a dns entry – Ôrel May 14 '21 at 08:15
  • I appreciate your help to this point but let me clarify with an example. A client should be able to make a GET request to http://my-gateway-url.com/serviceA/route and have Kong proxy this request to the relevant upstream serviceA/route ie a backend microservice. I have a DNS A record setup pointing my-gateway-url.com → the server of my Kong sever. How do I resolve requests to my-gateway-url.com the kong gateway running at localhost:8000 ? – Kuyashii May 14 '21 at 09:03
  • not sure to get what is your issue, if the dns resolution is working, there is nothing to change on this part, is your issue is on port 8000 ? Just configure kong to listen on port 80 not in port 8000. https://docs.konghq.com/gateway-oss/2.4.x/configuration/#proxy_listen – Ôrel May 14 '21 at 09:22
  • The DNS is not working, the following command just hangs with nor response: (not working) curl -i http://my-gateway-url.com:8000 But, if I call it from localhost as you described earlier with, works fine and I get a response from the upstream: (working) curl -i GET -H "Host: my-gateway-url.com" --header 'kong-debug: 1' 0.0.0.0:8000 My issue is how to configure to get the upstream to respond when calling just this: curl -i http://my-gateway-url.com:8000 – Kuyashii May 14 '21 at 09:55
  • What do you get with `nslookup my-gateway-url.com` ? Can you try with the host ip `curl -i GET -H "Host: my-gateway-url.com" --header 'kong-debug: 1' X.X.X.X:8000` ? Are you sure your host can get request from the outside ? – Ôrel May 15 '21 at 13:36