Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minikube expose MySQL running on localhost as service

Tags:

I have minikube version v0.17.1 running on my machine. I want to simulate the environment I will have in AWS, where my MySQL instance will be outside of my Kubernetes cluster.

Basically, how can I expose my local MySQL instance running on my machine to the Kubernetes cluster running via minikube?

like image 586
cgf Avatar asked Apr 11 '17 18:04

cgf


People also ask

How do you expose service in minikube?

Using minikube service with tunnel Services of type NodePort can be exposed via the minikube service <service-name> --url command. It must be run in a separate terminal window to keep the tunnel open. Ctrl-C in the terminal can be used to terminate the process at which time the network routes will be cleaned up.


2 Answers

Kubernetes allows you to create a service without selector, and cluster will not create related endpoint for this service, this feature is usually used to proxy a legacy component or an outside component.

  1. Create a service without selector

    apiVersion: v1 kind: Service metadata:     name: my-service spec:     ports:         - protocol: TCP           port: 1443           targetPort: <YOUR_MYSQL_PORT> 
  2. Create a relative Endpoint object

    apiVersion: v1 kind: Endpoints metadata:     name: my-service subsets:     - addresses:         - ip: <YOUR_MYSQL_ADDR>       ports:         - port: <YOUR_MYSQL_PORT> 
  3. Get service IP

    $ kubectl get svc my-service NAME         CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE my-service   <SERVICE_IP>   <none>        1443/TCP    18m 
  4. Access your MYSQL from service <SERVICE_IP>:1443 or my-service:1443

like image 125
Crazykev Avatar answered Nov 18 '22 13:11

Crazykev


As of minikube 1.10, there is a special hostname host.minikube.internal that resolves to the host running the minikube VM or container. You can then configure this hostname in your pod's environment variables or the ConfigMap that defines the relevant settings.

like image 34
David Maze Avatar answered Nov 18 '22 12:11

David Maze