MySQL cluster examples.
The following example will create a MySQL Cluster with 3 members, one primary and 2 secondaries:
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-test-cluster
spec:
members: 3The following example will create a MySQL Cluster with 3 primary (read/write) members:
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-multimaster-cluster
spec:
multiMaster: true
members: 3Create your own secret with a password field
$ kubectl create secret generic mysql-root-user-secret --from-literal=password=foobar
Create your cluster and reference it
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-custom-secret
spec:
members: 1
rootPasswordSecret:
name: mysql-root-user-secretThe following example will create a MySQL Cluster with a persistent local volume.
---
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
type: local
name: mysql-local-volume
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 10Gi
hostPath:
path: /tmp/data
persistentVolumeReclaimPolicy: Recycle
storageClassName: manual
---
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-with-volume
spec:
members: 1
volumeClaimTemplate:
metadata:
name: data
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1GiThe following example will create a MySQL Cluster with a persistent local data volume and a persistent local backup/restore volume.
---
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
type: local
name: mysql-local-volume
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 10Gi
hostPath:
path: /tmp/data1
persistentVolumeReclaimPolicy: Recycle
storageClassName: manual
---
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
type: local
name: mysql-local-backup-volume
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 10Gi
hostPath:
path: /tmp/data2
persistentVolumeReclaimPolicy: Recycle
storageClassName: manual
---
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-with-volume
spec:
members: 1
rootPasswordSecret:
name: mysql-root-user-secret
volumeClaimTemplate:
metadata:
name: data
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
backupVolumeClaimTemplate:
metadata:
name: backup-data
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1GiBy default, the MySQL Operator starts a cluster with an opinionated set of defaults.
However, you may wish to configure some aspects of your cluster through a my.cnf config file. This can be achieved by creating a config map and referencing it as part of your cluster spec.
First we create a config map containing the configuration file we want to apply to our cluster.
kubectl create configmap mycnf --from-file=examples/my.cnf
Now we can reference our config map in our cluster spec definition. For example:
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-with-config
members: 3
config:
name: mycnfBy default, the MySQL Operator starts a cluster with --server_id set to 1000 and increments it by one for each new cluster member. You can change this behavior by setting the baseServerId field on your Cluster. baseServerId value can be set to anything in the range from 1 to 4294967286. 0 is also accepted, but then the default value of 1000 will be used.
The following example will create a MySQL Cluster with following server_id's: 42,43,44
apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-with-custom-serverid
members: 3
baseServerId: 42