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

Time:08-17

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?

CodePudding user response:

One option would be Kubernetes Node Port Service can be defined

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

CodePudding user response:

Its not safe to expose the database publicly, but if you still want to reach then better to whitelist the IPs

  • Expose the db using TCP load balancer
  • Expose using the Node Port

With TCP load balancer, you will get the advantage of whitelisting the IPs. Here is AWS NLB example.

apiVersion: v1
kind: Service
metadata:
  name: db-tcp-servie
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"     
    service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
    service.beta.kubernetes.io/aws-load-balancer-name: "db-nlb"
spec:
  type: LoadBalancer
  loadBalancerSourceRanges:
  - "my-allowed-ip/32"
  - "11.22.33.44/32"
  selector:
    app.kubernetes.io/name: db-pod-selector
    app.kubernetes.io/instance: db-pod-selector
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306

Or you can consider the node-port service

A NodePort is an open port on every node of your cluster. Kubernetes transparently routes incoming traffic on the NodePort to your service, even if your application is running on a different node.

kubernetes-ingress-nodeport-load-balancers-and-ingress-controllers

  • Related