This is a Kubernetes operator that provisions databases on external database services. Right now it supports the following backends and more will be added.
- MySQL / MariaDB
- Apply to your cluster
kubectl apply -f https://github.com/krystal/database-provisioner/releases/latest/download/manifest.yaml
- Add appropriate CRs as shown below.
Apply a default MySQLServer
CR to your cluster with details for an external service.
apiVersion: databases.k8s.k.io/v1
kind: MySQLServer
metadata:
name: default
spec:
host: 185.22.208.10
port: 3306
username: root
password: 5up3r53cr3t
Apply a MySQLDatabase
CR to your cluster to create a database.
apiVersion: databases.k8s.k.io/v1
kind: MySQLDatabase
metadata:
name: my-database
namespace: some-namespace
spec:
serverName: default
connectionDetailsSecretName: db-connection
- This will use the
default
server - This will create a secret called
db-connection
containing details for the database connection. This secret will be created in the same namespace as theMySQLDatabase
CR. It will have values forhost
,username
,password
, anddatabaseName
.
You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info
shows).
- Install Instances of Custom Resources:
kubectl apply -f config/samples/
- Build and push your image to the location specified by
IMG
:
make docker-build docker-push IMG=<some-registry>/database-provisioner:tag
- Deploy the controller to the cluster with the image specified by
IMG
:
make deploy IMG=<some-registry>/database-provisioner:tag
To delete the CRDs from the cluster:
make uninstall
UnDeploy the controller from the cluster:
make undeploy
- Install the CRDs into the cluster:
make install
- Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run
NOTE: You can also run this in one step by running: make install run
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
make manifests
NOTE: Run make --help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation