0

Current scenario

I have,

  • a working minikube k8s cluster
  • a working MySQL server running on my Ubuntu 22.04.1 LTS machine (not deployed on docker or k8s)

Requirement

I'm actually trying to change the default database for WSO2IS_IDENTITY_DB of WSO2 Identity Server on k8s. But that really doesn't matter for the core of question. What I really want to do is, use some IP in the below url attribute so that the identity server can use it to store the data. I don't know what IP should be used here (in the deployment.toml config file)

    [database.identity_db]
    type = "mysql"
    url = "jdbc:mysql://192.168.X.X:3306/WSO2IS_IDENTITY_DB?autoReconnect=true&useSSL=false"
    username = "dbusername"
    password = "dbpassword"
    driver = "com.mysql.cj.jdbc.Driver"
    [database.identity_db.pool_options]
    validationQuery = "SELECT 1"

Attached is an image for understanding the requirement. I need an approach to the middle part marked "??" in the image below.

enter image description here

PS- I know this can be bad practice but I want to learn how this works and that's why I'm trying to connect this way.

I'm still learning k8s so any pointers to solve this problem (if at all possible) would be highly appreciated! Thanks.

I tried setting the output IP from the minikube ssh 'grep host.minikube.internal /etc/hosts | cut -f1' command as

    [database.identity_db]
    type = "mysql"
    url = "jdbc:mysql://192.168.X.X:3306/WSO2IS_IDENTITY_DB?autoReconnect=true&useSSL=false"
.....

but still no luck.

I have a vague idea that this has something to do with port mapping but not sure how can I achieve that.

Similar SO questions had answers where the external MySQL runs inside a docker container but in my case I want to access the MySQL server running on the Ubuntu localhost itself.

What solves my issue

If I can show tables inside the WSO2IS_IDENTITY_DB in my local machine and see all the relevant tables have been created by the WSO2 IS.

David Maze
  • 130,717
  • 29
  • 175
  • 215
RukshanJS
  • 791
  • 1
  • 7
  • 20
  • What is the error you get at the wso2 IS server logs? – Pubci Mar 09 '23 at 08:05
  • Make sure you have done the changes mentioned in step 7 and 8. https://apim.docs.wso2.com/en/latest/install-and-setup/setup/setting-up-databases/changing-default-databases/changing-to-mysql/#setting-up-mysql – Pubci Mar 09 '23 at 08:14
  • Can you run the database inside the cluster too? Then you can use its Service name as a host name. This will probably be easier to translate into other environments. The [Host access](https://minikube.sigs.k8s.io/docs/handbook/host-access/) page in the Minikube documentation also might help you. – David Maze Mar 09 '23 at 11:42
  • Also see [Access mysql running on localhost from minikube](https://stackoverflow.com/questions/55164223/access-mysql-running-on-localhost-from-minikube) or [Minikube expose MySQL running on localhost as service](https://stackoverflow.com/questions/43354167/minikube-expose-mysql-running-on-localhost-as-service) (in both cases, referring to the host system and not the different `localhost` in each pod). – David Maze Mar 09 '23 at 11:44

1 Answers1

0

Hope you can connect to the mysql server from localhost machine.

Then lets try to debug the root cause by creating a mysql client pod. You can run a mysql client installed pod in minikube with below command.

kubectl run mysql-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.32-debian-11-r11 --command -- bash

This will bring up a bash shell. Then try to connect to the local mysql server by below command.

mysql -h host.minikube.internal -uroot -p

This will prompt to enter the password. After giving the password it should connect to the server or it should give an error.