Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect to MySQL on Kubernetes with DBeaver directly instead of using kubectl port-forward?

Currently connecting to MySQL on Kubernetes with DBeaver after run the following command on terminal.

kubectx arn:aws:eks:XXX:cluster/XXX && kubens XXX && kubectl port-forward --address 0.0.0.0 XXX 13306:3306

I am looking for a way to do port-forwarding directly on DBeaver, as it is tedious to run the command every time and then connect with DBeaver.

What are some possible ways to do this?

like image 816
meowe__ Avatar asked Nov 02 '25 04:11

meowe__


1 Answers

Its possible to run kubectl port-forward before connecting automatically.

  1. Create a directory 'dbeaver-scripts' with a subfolder 'before-connect'.
  2. Create a shell-script, I named it my database connections name 'database-name.sh'
  3. Example shell script:
#!/usr/bin/env bash
export PATH='' # note that you need to set you path to include all dependencies default path of the dbeaver shell contains almost nothing.
echo "connect to database-name"
aws sso login --profile your-profile
kubectx arn:aws:eks:XXX:cluster/XXX 
kubens XXX
kubectl port-forward --address 0.0.0.0 XXX 13306:3306
echo "connection closed"
  1. Give the script excution rights chmod +x database-name.sh

  2. Test script by running it via your terminal.

    • If your script works in terminal but not in dbeaver; please echo your PATH 'echo $PATH' and copy it over into your script. As dbeaver's shell is pretty minimal on what it includes in its PATH.
  3. Edit your db connection its configuration. In the UI you will find a 'Shell commands' tab which has a setting called 'Before connect'.

  4. set the working directory to the before-connect folder

  5. set the command to /bin/bash -c "./database-name.sh"

  6. Pause before connecting for the amount of seconds you need for your script to run (I set it to a safe 10000ms)

like image 98
Max Visser Avatar answered Nov 03 '25 18:11

Max Visser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!