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?
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.
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.
Create a service without selector
apiVersion: v1 kind: Service metadata: name: my-service spec: ports: - protocol: TCP port: 1443 targetPort: <YOUR_MYSQL_PORT>
Create a relative Endpoint object
apiVersion: v1 kind: Endpoints metadata: name: my-service subsets: - addresses: - ip: <YOUR_MYSQL_ADDR> ports: - port: <YOUR_MYSQL_PORT>
Get service IP
$ kubectl get svc my-service NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-service <SERVICE_IP> <none> 1443/TCP 18m
Access your MYSQL from service <SERVICE_IP>:1443
or my-service:1443
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With