How to run multiple service on kong with different ports

@Arpit_Khandelwal I believe you can solve this using the KONG_PROXY_LISTEN and the route hosts configurations.

I tried the following. I ran a quickstart of the gateway using the following quickstart command binding the desired listen ports (port 8000 is bound by default)

curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_PROXY_LISTEN='0.0.0.0:8000,0.0.0.0:9000' -p 9000:9000

Then installed two services:

curl -i -s -X POST http://localhost:8001/services --data name=google_service --data url='https://google.com'
curl -i -s -X POST http://localhost:8001/services --data name=facebook_service --data url='https://facebook.com'

And two routes this way:

curl -i -X POST http://localhost:8001/services/google_service/routes --data name=google_route --data 'hosts[]=localhost:8000'
curl -i -X POST http://localhost:8001/services/facebook_service/routes --data name=facebook_route --data 'hosts[]=localhost:9000'

Then try routing requests to the desired data plane port:

curl localhost:8000
curl localhost:9000

Hope this helps.

1 Like