Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql remote connect over ssh to a kubernetes pod

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 ?

like image 303
Sina Miandashti Avatar asked Mar 04 '23 20:03

Sina Miandashti


1 Answers

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 
like image 120
helmbert Avatar answered Mar 13 '23 03:03

helmbert