Many devops use mysql connect over ssh to access to production database for various reasons and queries
after successfull deploy mysql container to a digital ocean kubernetes cluster im able to ssh into the pod via :
kubectl --kubeconfig="kubeconfig.yaml" exec -it vega-mysql-5df9b745f9-c6859 -c vega-mysql -- /bin/bash
my question is how can i remote connect applications like : navicat - sequel pro or mysql workbench to this pod ?
I achieved this by expose mysql to a service with random port
kubectl --kubeconfig=vega-kubeconfig.yaml expose deployment mysqldeployment --type=NodePort --name=nginx --port=3306 --target-port=3306
And connect to it via my client without ssh tunnel.
but @helmbert solution is good also
Nitpick: Even though you can use it to start an interactive shell, kubectl exec
is not the same as SSH. For that reason, regular MySQL clients that support SSH-tunneled connections, don't (and probably never will) support connecting to a MySQL server tunneled through kubectl exec
.
Alternative solution: Use kubectl port-forward
to forward the Pod's MySQL server port 3306 to your local machine:
kubectl port-forward vega-mysql-5df9b745f9-c6859 3306:3306
This will instruct kubectl to act as a TCP proxy from a local port on your machine into the Pod. Then, connect to 127.0.0.1:3306
with any MySQL client of your choice:
mysql -u youruser -p -h 127.0.0.1