MySQL Operator for Kubernetes Manual  /  MySQL InnoDB Cluster  /  Manifest Changes for InnoDBCluster

3.3 Manifest Changes for InnoDBCluster

This section covers common options defined while setting up a MySQL InnoDB Cluster. For a full list of options, see Table 8.1, “Spec table for InnoDBCluster”.

Here's a simple example that uses most defaults:

Press CTRL+C to copy
apiVersion: mysql.oracle.com/v2 kind: InnoDBCluster metadata: name: mycluster spec: secretName: mypwds tlsUseSelfSigned: true

Here's an expanded version of that with optional changes:

Press CTRL+C to copy
apiVersion: mysql.oracle.com/v2 kind: InnoDBCluster metadata: name: mycluster spec: secretName: mypwds tlsUseSelfSigned: true instances: 3 version: 9.1.0 router: instances: 1 version: 9.1.0 datadirVolumeClaimTemplate: accessModes: - ReadWriteOnce resources: requests: storage: 40Gi initDB: clone: donorUrl: mycluster-0.mycluster-instances.another.svc.cluster.local:3306 rootUser: root secretKeyRef: name: mypwds mycnf: | [mysqld] max_connections=162

Below are explanations of each change made to initial the InnoDBCluster configuration.

Router and Server Versions and Instances

By default, MySQL Operator for Kubernetes installs MySQL Server with the same version as the Operator, and installs Router with the same version as MySQL Server. It also installs 3 MySQL instances and 1 Router instance by default. Optionally configure each:

Press CTRL+C to copy
spec: instances: 3 version: 9.1.0 router: instances: 1 version: 9.1.0

Setting PersistentVolumeClaim Size

Set a MySQL instance's storage configuration. For storing the MySQL Server's Data Directory (datadir), a PersistentVolumeClaim (PVC) is used for each MySQL Server pod. Each PVC follows the naming scheme datadir-{clustername}-[0-9]. A datadirVolumeClaimTemplate template allows setting different options, including size and storage class. For example:

Press CTRL+C to copy
datadirVolumeClaimTemplate: accessModes: - ReadWriteOnce resources: requests: storage: 40Gi

For additional configuration information, see the official Storage: Persistent Volumes documentation. The datadirVolumeClaimTemplate object is set to x-kubernetes-preserve-unknown-fields: true.

Note

MySQL Operator for Kubernetes currently does not support storage resizing.

For a related MySQLBackup example that uses a PersistentVolumeClaim, see Section 7.1, “Handling MySQL Backups”.

The initDB Object

Optionally initialize an InnoDBCluster with a database using the initDB object; it's only used when the InnoDBCluster is created. It accepts clone or dump definitions.

This simple initDB clone example clones a remote MySQL instance from a cluster. The donor MySQL server's credentials are stored in a Secret on the target server with a 'rootPassword' key for the 'rootUser'.

Press CTRL+C to copy
initDB: clone: donorUrl: mycluster-0.mycluster-instances.another.svc.cluster.local:3306 rootUser: root secretKeyRef: name: mypwds

MySQL Server restarts after populating with the clone operation, and a "1" is seen in the restart column of the associated pods. Cloning utilizes MySQL Server's The Clone Plugin and behaves accordingly.

For a dump example (instead of clone), see Section 7.2, “Bootstrap a MySQL InnoDB Cluster from a Dump using Helm”.

Modify my.cnf Settings

Use the mycnf option to add custom configuration additions to the my.cnf for each MySQL instance. This example adds a [mysqld] section that sets max_connections to 162:

Press CTRL+C to copy
mycnf: | [mysqld] max_connections=162

This is added to the generated my.cnf; the default my.cnf template is visible in the initconf container's ConfigMap. An example to see this template: kubectl get cm ${CLUSTER_NAME}-initconf -o json | jq -r '.data["my.cnf.in"]'.