我已经在Google Kubernetes Engine和Google Cloud SQL上搭建了一个应用程序堆栈。在本地开发时,我希望我的应用程序连接到运行在集群外部的postgres数据库服务器,以模拟生产环境。
看来要做到这一点,需要按照这里描述的方式定义一个外部端点:Minikube expose MySQL running on localhost as service
不幸的是,我不能将"127.0.0.1"指定为端点IP地址:
kubectl apply -f kubernetes/local/postgres-service.yaml
service "postgres-db" unchanged
The Endpoints "postgres-db" is invalid: subsets[0].addresses[0].ip:
Invalid value: "127.0.0.1": may not be in the loopback range (127.0.0.0/8)
所以我被迫将Postgres绑定到我的实际机器地址。
似乎一定有一种方法可以将本地主机的端口映射到本地kubernetes集群中,但到目前为止我找不到方法。
有人知道窍门吗?或者,是否有人可以建议一种不涉及在集群内运行postgres的替代方案?
jdbc:postgresql://host.docker.internal:5432/postgres
作为环境变量传递给我的 DB_URL,它就成功连接了。无需创建额外的服务。 - orpheus