percona / everest

Percona Everest is a cloud-native database platform to deploy and manage enterprise-grade PostgreSQL, MongoDB and MySQL database clusters.
https://docs.percona.com/everest/index.html
Apache License 2.0
253 stars 12 forks source link

Information request: How to connect to the database #713

Open nvsajeeva opened 2 months ago

nvsajeeva commented 2 months ago

Hello, I have created a database with external access = false. Please kindly let me know how I can access it.

k get db -A
NAMESPACE   NAME        SIZE   READY   STATUS   HOSTNAME                    AGE
everest     sajeevadb   2      2       ready    sajeevadb-haproxy.everest   16m

k get services -n everest

NAME                              TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                                 AGE
percona-xtradb-cluster-operator   ClusterIP   10.97.23.85    <none>        443/TCP                                 31m
sajeevadb-haproxy                 ClusterIP   10.99.180.88   <none>        3306/TCP,3309/TCP,33062/TCP,33060/TCP   15m
sajeevadb-haproxy-replicas        ClusterIP   10.109.9.147   <none>        3306/TCP                                15m
sajeevadb-pxc                     ClusterIP   None           <none>        3306/TCP,33062/TCP,33060/TCP            15m
sajeevadb-pxc-unready             ClusterIP   None           <none>        3306/TCP,33062/TCP,33060/TCP            15m
recharte commented 2 months ago

Hi @nvsajeeva, since you didn't enable external access, the provisioned DB is only accessible by clients living inside your k8s cluster.

Gathering connection info

In order to connect to it you'll need 2 things:

  1. hostname or IP address
  2. root user's password

You can easily get both of these from the UI but if you want to do it through the shell here's how:

  1. kubectl get db <YourDBName> -n <YourDBNamespace> -o jsonpath='{.status.hostname}' But you already found this out, it's sajeevadb-haproxy.everest(10.99.180.88).
  2. kubectl get secret everest-secrets-<YourDBName> -n <YourDBNamespace> -o go-template='{{.data.root|base64decode}}'

Connecting

For testing purposes, you can run a container with mysql tool and connect its console output to your terminal. In a real scenario, you'd configure your application instead. Here's how to test it:

  1. Run the client application:

    kubectl run -n everest -i --rm --tty percona-client --image=percona:8.0 --restart=Never -- bash -il

    Executing it may require some time to deploy the corresponding Pod.

  2. Now run the mysql tool in the percona-client command shell using the password obtained from the Secret instead of the placeholder.

    mysql -h <YourDBHostname> -uroot -p'<RootPassword>'