This topic describes the available fields of the VMware MySQL Custom Resource Definition.
apiVersion: with.sql.tanzu.vmware.com/v1
kind: MySQL
metadata:
name: mysql-sample
spec:
#### Specify the MySQL Version
# mysqlVersion:
# name: mysql-8.0.34
#### Set the storage size for the database persistent storage volume
# storageSize: 1Gi
# imagePullSecretName: tanzu-image-registry
#### Set the storage class name to change storage class of the PVC associated with this resource
# storageClassName: standard
#### Set the type of Service used to provide access to the MySQL database.
# serviceType: LoadBalancer
#### Set the name of the Secret used for TLS
# tls:
# secret:
# name: mysql-tls-secret
#### Set the name of the Secret used for LDAP CA
# trustedCertificates:
# ldap:
# name:
### Set the policy to Retain or Delete so that PVCs are either saved or deleted when MySQL is deleted
# persistentVolumeClaimPolicy: Delete
#### Enable highly available cluster
# highAvailability:
# enabled: true
# members: 3
#### Set the name of the ConfigMap to customize MySQL server configuration
# customConfig:
# name: my-custom-config
#### Enable affinity
# databasePodConfig:
# affinity:
# podAntiAffinity:
# preferredDuringSchedulingIgnoredDuringExecution:
# - weight: 1
# podAffinityTerm:
# topologyKey: "kubernetes.io/hostname"
# labelSelector:
# matchExpressions:
# - key: "app.kubernetes.io/component"
# operator: In
# values:
# - database
# - key: "app.kubernetes.io/instance"
# operator: In
# values:
# - mysql-sample
# tolerations:
# - key: node.kubernetes.io/disk-pressure
# operator: "Exists"
# effect: "NoExecute"
# tolerationSeconds: 3600
# proxyPodConfig:
# affinity:
# podAntiAffinity:
# preferredDuringSchedulingIgnoredDuringExecution:
# - weight: 1
# podAffinityTerm:
# topologyKey: "kubernetes.io/hostname"
# labelSelector:
# matchExpressions:
# - key: "app.kubernetes.io/component"
# operator: In
# values:
# - proxy
# - key: "app.kubernetes.io/instance"
# operator: In
# values:
# - mysql-sample
# tolerations:
# - key: node.kubernetes.io/memory-pressure
# operator: "Exists"
# effect: "NoExecute"
# tolerationSeconds: 3600
#### Examples to set resource limit/request for mysql/backup containers.
# resources:
#### This is the container running the mysql server.
# mysql:
# requests:
# cpu: 750m
# memory: 500Mi
# limits:
# cpu: '1.0'
# memory: 1Gi
#### This is the sidecar container that manages backups and innodb cluster operations
# mysqlSidecar:
# requests:
# cpu: 100m
# memory: 50Mi
# limits:
# cpu: 250m
# memory: 256Mi
#### This is the container that proxies connections to MySQL
# proxy:
# requests:
# cpu: 200m
# memory: 48Mi
# limits:
# cpu: '1.0'
# memory: 256Mi
#### This is the container that exports metrics
# metrics:
# requests:
# cpu: 100m
# memory: 32Mi
# limits:
# cpu: 250m
# memory: 75Mi
Applying this resource causes the Kubernetes Operator to create a StatefulSet with a single Pod and three containers. One container runs the MySQL database software, one runs the components to support backups, and the third runs the mysqld_exporter (for monitoring). The MySQL pod mounts a persistent volume claim (PVC) which holds the MySQL data.
You specify MySQL instance configuration properties to the MySQL operator with a YAML-formatted manifest file. A sample manifest file is provided in mysql.yaml
. See also Creating and Deleting Instance for information about deploying a new MySQL instance using a manifest file.
The list below explains the properties that you can set in your MySQL resource.
Type: string
Required
Default: standard
The name of the MySQL instance. Must be unique within a namespace. Cannot be modified after the MySQL instance has been created. The metadata can set the name, namespace, labels, annotations, and more for the MySQL object. For more information, see the Kubernetes documentation.
Example: mysql-sample
Type: string
Optional
Default:
The MySQL version that will be used for creating an instance. If the user does not specify a value, the latest supported version will be used as the default. For example, if the VMware MySQL Operator supports mysql-8.0.28, mysql-8.0.29, mysql-8.0.31, and mysql-8.0.32 this value defaults to mysql-8.0.32.
Each Operator release supports several MySQL versions. Only the permitted version strings are valid input for the field. Entries that do not match a supported version generate an error. Use
kubectl get mysqlversion
to verify the MySQL versions of your Operator release.
Use the “floating version tag”
mysql-latest
to configure your instance to always upgrade to the latest MySQL version supported by future Operator upgrades.
Example:
mysql-8.0.32
CautionAfter an Operator upgrade, instances with
mysqlVersion.name
asmysql-latest
will automatically reboot and upgrade to the latest supported MySQL version for that Operator.
Type: quantity
Optional
Default: 1Gi
The size of the persistent volume claims (PVCs) for MySQL instance Pods. Specify a suffix for the units (for example: 100G, 1T). After being set, cannot be reduced, but can be increased. For information about allowed size units, see the discussion about resource quantities in the Kubernetes resource model in the community GitHub repository.
Example: 50Gi
Type: string
Optional
Default: Defaults to the imagePullSecretName:
used during Operator deployment, as set in the Operator’s values.yaml
. See Configure a Kubernetes Secret for Accessing the Private Container Registry.
Note that the secret may need to be recreated within your pod’s namespace in order for your pod to access it.
An existing Kubernetes docker-registry secret that can access the registry containing the MySQL image.
Example: tanzu-image-registry
Type: string
Optional
Default: standard
The StorageClass used for PVCs associated with MySQL instance Pods. Cannot be modified after the MySQL instance has been created. For available types, contact your Kubernetes admin. For information about the StorageClass concept, see the Kubernetes documentation.
Example: standard
Type: string
Optional
Default: ClusterIP
The type of Service used to provide access to the MySQL database. Only ClusterIP
and LoadBalancer
are supported. For more information about Kubernetes ServiceTypes, see the Service Types in the Kubernetes documentation.
Example: LoadBalancer
Type: string
Optional
Default: n/a
The name of the Kubernetes secret containing the TLS certificate and private key used to support encrypted connections by clients. For more configuration details, see Configuring TLS for MySQL Instances
Example: mysql-tls-secret
Type: string
Optional
Default: n/a
The name of the Kubernetes secret containing the certificate authority for an LDAP server. The secret must contain a key named ca.crt
that contains a PEM formatted certificate. Example: ldap-ca-secret
Type: boolean
Optional
Default: false, unless highAvailability.members
is greater than 1
Whether the instance is a high-availability cluster (not single-node). After being set to true
, it cannot be modified. For information about high availability, see Configuring MySQL Instances for High Availability.
Example: true
Type: integer
Optional
Default: 3 when highAvailability.enabled
is true
Total number of members in the HA cluster. Can be 3, 5, 7, or 9. A value of 1 would be a single instance. An even number creates the potential for a split-brain scenario, which must be avoided. For information about HA members, see Change Number of Members in HA MySQL Instance.
Example: 5
Type: string
Optional
Default: n/a
The name of the Kubernetes ConfigMap containing MySQL configuration. For more configuration details, see Customizing the MySQL Server
Example: mysql-custom-config
Type: corev1.Affinity
Optional
Default: Database pods for a given instance are scheduled in unique Kubernetes nodes.
The affinity rules for the MySQL database pods must follow the affinity defined by the Kubernetes api, can be updated, and are not required when creating resources. For more information regarding the various fields, see the Affinity and Anti-Affinity in the Kubernetes documention.
Example:
apiVersion: with.sql.tanzu.vmware.com/v1
kind: MySQL
metadata:
name: my-instance
spec:
databasePodConfig:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: "kubernetes.io/hostname"
labelSelector:
matchExpressions:
- key: "app.kubernetes.io/component"
operator: In
values:
- database
- key: "app.kubernetes.io/instance"
operator: In
values:
- <instance.name>
Type: corev1.Toleration
Optional
Default: No default tolerations are configured by the VMware MySQL Operator.
Configures Kubernetes Tolerations for the MySQL instance’s database Pods. The Tolerations can be updated, and are not required when creating resources. For more details on the Kubernetes Taints and Tolerations concept, see Taints and Tolerations in the Kubernetes documentation.
Example:
---
apiVersion: with.sql.tanzu.vmware.com/v1
kind: MySQL
metadata:
name: my-instance
spec:
databasePodConfig:
tolerations:
- key: node.kubernetes.io/memory-pressure
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 3600
Type: corev1.Affinity
Optional
Default: Preference is to avoid scheduling the two proxy pods on the same Kubernetes node.
Affinity rules for the Proxy database pods. Used only when spec.highAvailability.enabled = true. For more information regarding the various fields, see the Affinity and Anti-Affinity in the Kubernetes documention.
Example:
apiVersion: with.sql.tanzu.vmware.com/v1
kind: MySQL
metadata:
name: my-instance
spec:
databasePodConfig:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: "kubernetes.io/hostname"
labelSelector:
matchExpressions:
- key: "app.kubernetes.io/component"
operator: In
values:
- proxy
- key: "app.kubernetes.io/instance"
operator: In
values:
- <instance.name>
Type: corev1.Toleration
Optional
Default: No default tolerations are configured by the VMware MySQL Operator
Configures Kubernetes Tolerations for the MySQL instance’s database Pods. For more details on the Kubernetes Taints and Tolerations concept, see Taints and Tolerations in the Kubernetes documentation.
Example:
---
apiVersion: with.sql.tanzu.vmware.com/v1
kind: MySQL
metadata:
name: my-instance
spec:
databasePodConfig:
tolerations:
- key: node.kubernetes.io/memory-pressure
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 3600
Type: object
Optional
This object is a mapping of strings to ResourceRequirements
that describes the compute resource requirements (requests and limits of cpu and memory).
The supported keys are mysql
, mysql-sidecar
, proxy
, and metrics
. The mysql
resources apply to the container running MySQL in the data pod. The mysql-sidecar
resources apply the container that reconciles MySQL and MySQLBackup in the sidecar container. The metrics
resources apply to the container running the Prometheus exporter in another sidecar. The proxy
resources apply to the container running the MySQL Router in the proxy pods.
Memory specifies the amount of memory allocated to a container and defines a memory limit; if a pod tries to exceed the limit, the pod is removed and replaced by a new pod. Memory units may use a suffix, for example, 4.5Gi
. For more details on resource allocation in Kubernetes, see Assign Memory Resources to Containers and Pods in the Kubernetes documentation.
CPU is the amount of CPU resources allocated to a container, specified as a Kubernetes CPU unit. For example: cpu: "1.2"
. If left empty, it inherits the default limit of its namespace (if a limit exists), or has no limit on CPU consumed. For more details on resource allocation in Kubernetes, see Assign CPU Resources to Containers and Pods in the Kubernetes documentation.
mysql:
requests:
cpu: 750m
memory: 500Mi
limits:
cpu: '1.0'
memory: 1Gi
mysqlSidecar:
requests:
cpu: 100m
memory: 512Mi
limits:
cpu: 250m
memory: 512Mi
proxy:
requests:
cpu: 200m
memory: 48Mi
limits:
cpu: '1.0'
memory: 256Mi
metrics:
requests:
cpu: 100m
memory: 32Mi
limits:
cpu: 250m
memory: 75Mi
Note: These values are examples of values only. They are not recommended values.
In some environments, 1Gi
is too low of a memory limit for the MySQL container and will cause the OOMKiller to terminate the container.
kubectl describe pod mysql-sample-0
...
Containers:
mysql:
...
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Started: Mon, 12 Jun 2023 14:53:09 -0700
Finished: Mon, 12 Jun 2023 14:53:11 -0700
If the Metrics API is installed on the Kubernetes cluster, you can view the resource metrics for pods using the kubectl top
command. See Resource metrics pipeline for more information.
For example,
kubectl top pods
NAME CPU(cores) MEMORY(bytes)
mysql-sample-0 96m 863Mi
mysql-sample-1 58m 645Mi
mysql-sample-2 34m 648Mi
mysql-sample-proxy-0 13m 6Mi
mysql-sample-proxy-1 14m 6Mi
To achieve a certain Quality of Service, you must configure the resource requirements of the containers accordingly.
Type: string
Optional
Default: Retain
Describes the PVC retention policy when the associated MySQL instance is deleted. Values can be Retain
or Delete
.
Example: Delete