How to use Ambassador api gateway as a PostgreSQL-aware proxy?

11/6/2018

I am using Ambassador to manage my Kubernetes services. My Kubernetes services consist of a few web servers and a few postgres. I followed the instructions hereto establish routes to my web servers. Here is an example:

  annotations:
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v1
      kind:  Mapping
      name:  somewebservice
      prefix: /somewebservice
      service: somewebservice:80

This works perfectly for my webserver. I can do curl localhost/somewebservice and I get the expected response.

I have set up the same annotation in my postgres container, but I cannot do a psql.

  annotations:
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v1
      kind:  Mapping
      name:  atlas
      prefix: /somepostgres
      service: somepostgres:5432

I see the following:

$ psql -h 'localhost/somepostgres' -p 5432
psql: could not translate host name "localhost/somepostgres" to address: nodename nor servname provided, or not known

My goal is to have Ambassador accept both HTTP/HTTPS & postgres requests. Thanks for your time.

-- fanoffan
envoyproxy
kubernetes
postgresql

1 Answer

11/6/2018

Postgres is a TCP service (Layer 4) and not an HTTP(s) service (Layer 7). It doesn't look like Ambassador supports TCP only services, even though the Envoy proxy supports it. So you'll have to do with a regular Kubernetes TCP service, something like this:

kind: Service
apiVersion: v1
metadata:
  name: postgres-svc
spec:
  selector:
    app: postgres
  ports:
  - protocol: TCP
    port: 5432
-- Rico
Source: StackOverflow