A tool to create databases inside an existing MySQL, like for example
- AWS RDS Aurora
- helm install stable/mysql
- Any other MySQL
This is published as a Docker image polarn/kubesdb.
Well, our problem was that we decided to have one RDS Aurora cluster on a private subnet and share it between all our micro services, by creating MySQL databases for each service inside it. We wanted to do this in an "infrastructure as code" way but it proved a bit difficult using SSH tunnels to a bastion host, etc...
So the idea is to use a Kubernetes pod to create the databases by listening on (watching) the Kubernetes API for secrets that match a certain label. Once a secret is created, a database and username/grant will be created.
We can now create the RDS, Kubernetes secrets, etc using Terraform. We're happy!
Create the RDS cluster using your favourite tool (we use Terraform) or using the UI.
We add them using the terraform kubernetes plugin
We put the following in our Secrets:
database
: Database nameusername
: The username of the grant to be createdpassword
: And the password to that granturl
: The JDBC URL (this is not needed for kubesdb but our micro service use it to connect to the database)
Examples:
or using kubectl
:
kubectl create secret generic kubesdb-secret --from-literal=database=test --from-literal=username=testuser --from-literal=password=$(openssl rand -hex 8) --from-literal=url=jdbc:mysql://examplerds.randomstring.region.rds.amazonaws.com:3306/test?useSSL=false
kubectl label secret kubesdb-secret kubesdb=true
In the repo there is an example file of how we use it: kubernetes/deployment.yaml
test2