Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information request: How to connect to the database #713

Open
nvsajeeva opened this issue Sep 24, 2024 · 2 comments
Open

Information request: How to connect to the database #713

nvsajeeva opened this issue Sep 24, 2024 · 2 comments

Comments

@nvsajeeva
Copy link

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
Copy link
Collaborator

recharte commented Sep 24, 2024

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.

  1. 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>'

@telderfts
Copy link

This probably pertains to #914 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants