Search code examples
kuberneteskong

Can't add internal API to KONG api gateway running on GKE


I'm running Kong API gateway on GKE and trying to add my own service.

I have 3 pods

  • cassandra
  • kong
  • apiindex

and 2 services(node ports)

  • apiindex (80/443/8080 ports are open)
  • kong-proxy(8000/8001/8443)

I'm trying to add apiindex api to API gateway using

curl -i -X POST http://kong-proxy:8001/apis -d 'name=test' -d 'uris=/' -d 'upstream_url=http://apiindex/'

But then http://kong-proxy:8000/ returns

503 {"message": "Service unavailable"}

It works fine when I add some public website inside curl -i -X POST http://kong-proxy:8001/apis -d 'name=test' -d 'uris=/' -d 'upstream_url=http://httpbin.org/'

curl http://apiindex/ returns 200 from kong pod.

Is it possible to add API using kong without exposing apiindex service?


Solution

  • You need to use the fully qualified name of the service (FQDN) in kubernetes https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/

    So instead of apiindex need to use apiindex.default.svc.cluster.local

    curl -i -X POST http://kong-proxy:8001/apis -d 'name=testapi' -d 'uris=/' -d 'upstream_url=http://apiindex.default.svc.cluster.local/'