MySQL with StorageOS
MySQL is a popular SQL open source database for a wide range of popular web-based applications including WordPress.
Before you start, ensure you have StorageOS installed and ready on a Kubernetes cluster. See our guide on how to install StorageOS on Kubernetes for more information.
Deploying MySQL on Kubernetes
You can find the latest files in the StorageOS use cases repository
git clone https://github.com/storageos/use-cases.git storageos-usecases
apiversion: apps/v1 kind: statefulset metadata: name: mysql spec: selector: matchlabels: app: mysql env: prod servicename: mysql replicas: 1 ... spec: serviceaccountname: mysql ... volumemounts: - name: data mountpath: /var/lib/mysql subpath: mysql - name: conf mountpath: /etc/mysql/mysql.conf.d ... volumeclaimtemplates: - metadata: name: data labels: env: prod spec: accessmodes: ["readwriteonce"] storageclassname: "fast" # storageos storageclass resources: requests: storage: 5gi
This excerpt is from the StatefulSet definition. This file contains the VolumeClaim template that will dynamically provision storage, using the StorageOS storage class. Dynamic provisioning occurs as a volumeMount has been declared with the same name as a VolumeClaim.
Move into the MySQL examples folder and create the objects
cd storageos-usecases kubectl create -f ./mysql
Confirm MySQL is up and running.
$ kubectl get pods -w -l app=mysql NAME READY STATUS RESTARTS AGE mysql-0 1/1 Running 0 1m
Connect to the MySQL client pod and connect to the MySQL server through the service
$ kubectl exec client -- mysql -h mysql-0.mysql -e "show databases;" Database information_schema mysql performance_schema
If you need custom startup options, you can edit the ConfigMap file 15-mysqld-configmap.yaml with your desired MySQL configuration settings.