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
There is a potential solution for this called Telepresence which allows to have a local workload to be proxied into the cluster as if it were actualy run within that kube cluster.
I had similar issues with developing cloud-native software directly inside Kubernetes. We took a look at tools like Telepresence and Skaffold, too but they are hard to configure and very time-consuming.
That's why I built the DevSpace CLI together with a colleague: https://github.com/covexo/devspace
Feel free to take a look and try it out. It will solve issues like yours by allowing you to easily run all your workloads directly inside Kubernetes while still being able to program with your desktop tools (local terminal, IDE, git etc).
As you are using minikube, you should take a look as the answers to this question: Routing an internal Kubernetes IP address to the host system
You could also use local tunneling with tools like ngrok: https://ngrok.com/ (simply start it locally and connect to your ngrok address from anywhere)
Mysql server should connect to private IP, and that private IP can be used in application.
Prefer way is to create kubernetes service+endpoint pointing to Mysql Server IP.
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.