Connect to local database from inside minikube cluster

minikube connect to localhost
kubernetes connect to external database
minikube postgres
kubernetes pod access external ip
minikube etc/hosts
connect to external ips from inside kubernetes pod
connect to redis in kubernetes
kubectl port-forward connection refused

I'm trying to access a MySQL database hosted inside a docker container on localhost from inside a minikube pod with little success. I tried the solution described Minikube expose MySQL running on localhost as service but to no effect. I have modelled my solution on the service we use on AWS but it does not appear to work with minikube. My service reads as follows

apiVersion: v1

kind: Service

metadata: 

  name: mysql-db-svc

  namespace: external

spec: 
  type: ExternalName
  ExternalName: 172.17.0.2

...where I try to connect to my database from inside a pod using "mysql-db-svc" on port 3306 but to no avail. If I try and CURL the address "mysql-db-svc" from inside a pod it cannot resolve the host name.

Can anybody please advise a frustrated novice?

This is because your service type is ExternalName which only fits in cloud environment such as AWS and GKE. To run your service locally change the service type to NodePort which will assign a static NodePort between 30000-32767. If you need to assign a static port on your own so that minikube won't pick a random port for you define that in your service definition under ports section like this nodePort: 32002.

And also I don't see any selector that points to your MySQL deployment in your service definition. So include the corresponding selector key pair (e.g. app: mysql-server) in your service definition under spec section. That selector should match with the selector you have defined in MySQL deployment definition.

So your service definition should be like this:

kind: Service
apiVersion: v1
metadata:
  name: mysql-db-svc
  namespace: external
spec:
  selector:
    app: mysql-server
  ports:
  - protocol: TCP
    port: 3306
    targetPort: 3306
    nodePort: 32002
  type: NodePort

After you deploy the service you can hit the MySQL service via http://{minikube ip}:32002 Replace {minikube ip} with actual minikube ip.

Or else you can get the access URL for the service with following command

minikube service <SERVICE_NAME> --url

Replace the with actual name of the service. In your case it is mysql-db-svc

Access to external database? · Issue #352 · kubernetes/minikube , Retargeting my question: Minikube sets up a local network on your host Access from inside a K8S cluster to external database via Internet? I have a local mysql running and I wanted to connect a pod running inside the  I'm trying to access to local MySQL database from minikube container. My minikube works on Windows 10 with hyper-v driver. I found a few solutions (creating host-only network from VirtualBox) but nothing for hyper-v. Can somebody assist me how can I connect to localhost mysql server from minikube hyper-v?

If I'm not mistaken, you should also create an Endpoint for this service as it's external.

In your case, the Endpoints definition should be as follows:

kind: "Endpoints"
apiVersion: "v1"
metadata:
  name: mysql-db-svc
  namespace: external
subsets: 
- addresses:
  - ip: "10.10.1.1"
  ports:
    port: 3306

You can read about the external sources on Kubernetes Defining a service docs.

How to access postgres running on host OS from inside minikube , Hello! I can't to connect to postgres on my local machine from minikube. I also try to clear all firewall rules (iptables -F, iptables -t nat -F) on local  If you run minikube ssh can you resolve any address from inside the vm? If on the host you run dig @$(minikube ip) database.NAMESPACE.svc.cluster.local (replace namespace appropriately) does that resolve correctly (this will be a cluster internal address so not routable from your host)?

I'm using ubuntu with Minikube and my database runs outside of minikube inside a docker container and can be accessed from localhost @ 172.17.0.2. My Kubernetes service for my external mysql container reads as follows:

kind: Service
apiVersion: v1
metadata:
  name: mysql-db-svc
  namespace: external
spec: 
  type: ExternalName
  externalName: 10.0.2.2

Then inside my .env for a project my DB_HOST is defined as

mysql-db-svc.external.svc

... the name of the service "mysql-db-svc" followed by its namespace "external" with "svc"

Hope that makes sense.

Minikube:Exposing mysql as a service on localhost, I am running minikube 0.17.1 on my local machine to simulate the environment for my mysql instance to the kubernetes cluster using minikube? I have followed the link which you have READ MORE · answered Jul 23  I've found the issue gets resolved if you remove the registry-proxy DaemonSet. when you enable the registry addon, it creates a Service which is loadbalancing across both the registry-proxy and the registry.

Minikube. How to allow access to local mySQL database from , addresses: - ip: "23.99.34.75" ports: - port: 3306. Also you can check this question Connect to local database from inside minikube cluster. Note that when you are using Minikube without a local Docker daemon (docker-for-windows) you need to instruct Docker CLI to send the commands to the remote docker daemon installed in the Minikube

Connecting to an external mysql database, I am trying to connect my spring-boot api inside a kubernetes pod to an external database (a separate machine but within the local network), i don't think you do a service as that setups an ip inside the k cluster right? Installing Kubernetes with Minikube. Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day. Minikube Features; Installation; Quickstart; Managing your Cluster; Interacting with Your Cluster

Installing Kubernetes with Minikube, Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a  The bridge IP will be the IP you connect to inside minikube. Note: You should be careful about opening up postgres to all remote IP. A safer way would be to only allow IPs from the minikube environment. For instance inside my minikube environment my bridge ip is 192.168.64.1.

Comments
  • Thanks for the feedback, greatly sppreciated. But the mysql instance is not inside the cluster, it's external to minikube.
  • could you please provide some more details on how you got it to work ?
  • Thanks! but this did not help, I am on a Mac and have mysql deployed locally. I want to access it from a spring boot application running on Minikube.
  • @prime That's impressive, but how did you figure out the magic externalName there? Where does the 10.0.2.2 come from?
  • Nevermind, this explains it: stackoverflow.com/a/34732276/1035008