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?
Asked
Active
Viewed 1.1k times
4
-
See "docker volume". – Rick James Mar 25 '20 at 16:40
3 Answers
3
Minikube v1.10 added a hostname to the cluster DNS that allows pods to connect to the host. Have your pods use this DNS entry to access the host IP. At this time, the DNS hostname is host.minikube.internal
See docs to learn more.

levibostian
- 133
- 4
1
First you need to create a Service
and then create an Endpoint
with the IP of your MySQL.
apiVersion: v1
kind: Service
metadata:
name: database
spec:
ports:
- port: 3306
targetPort: 3306
protocol: TCP
---
# Because this service has no selector, the corresponding Endpoints
# object will not be created. You can manually map the service to
# your own specific endpoints:
kind: Endpoints
apiVersion: v1
metadata:
name: database
subsets:
- addresses:
- ip: "23.99.34.75"
ports:
- port: 3306
Also you can check this question Connect to local database from inside minikube cluster.

Crou
- 739
- 3
- 10
-
Thanks for answer. How can I get mySql IP? Is it my external IP? – Denis Lopatin Mar 23 '20 at 12:34
-
I would deploy that MySQL inside a docker container so it would be easy to connect to. – Crou Mar 23 '20 at 12:55
-
1It is like an option. I thought about this. But for me looks like an extra job. – Denis Lopatin Mar 23 '20 at 12:58
0
Get your host ip by HOST_IP=$(minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'")
According to K8s docs apply:
apiVersion: v1
kind: Service
metadata:
name: mysql-db
spec:
ports:
- port: 3306
targetPort: 3306
protocol: TCP
---
kind: EndpointSlice
apiVersion: discovery.k8s.io/v1
metadata:
name: mysql-db-endpoint
labels:
kubernetes.io/service-name: mysql-db
addressType: IPv4
ports:
- port: 3306
name: ''
appProtocol: http
protocol: TCP
endpoints:
- addresses:
- $HOST_IP