During local development with Kubernetes/minikube, how should I connect to postgres database running on localhost?

前端 未结 4 1467
太阳男子
太阳男子 2021-01-02 02:24

I\'ve set up an application stack running on Google Kubernetes Engine + Google Cloud SQL. When developing locally, I would like my application to connect to a postgres datab

4条回答
  •  忘掉有多难
    2021-01-02 02:50

    May not be an answer for Minikube, but I ended up here so I share what I did for Kubernetes in Docker for Mac.

    I added a service like this for PostgreSQL:

    kind: Service
    apiVersion: v1
    metadata:
      name: postgres
      namespace: default
    spec:
      type: ExternalName
      # https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
      externalName: host.docker.internal
      ports:
        - name: port
          port: 5432
    

    My application was able to connect to the locally running postgres server with this setup using the domain name postgres. The Postgres server can listen to 127.0.0.1 with this setup.

提交回复
热议问题