Cennso Database Instance
A Cennso Database Instance is represented by the DBInstance Custom Resource (CR) and defines a MySQL cluster managed by the Cennso Database Operator.
Important
Before deploying the MySQL cluster, you must have the Database Operator up and running.
The sections below provide information about configuration parameters that you can specify in the DBInstance CR. For more information on how to configure and deploy the database cluster, see the Deploy Cennso Database and Cennso Database Instance Custom Resource Definition documents.
Naming constraint
Important
The DBInstance metadata.name must not exceed 15 characters.
The Cennso Database extension derives the names of the MySQL cluster resources (the underlying MySQL custom resource, the StatefulSet pods, PVCs, and the HAProxy Service) from the DBInstance metadata.name, with a fixed prefix ps-db- that is added automatically. The combined name is bound by an upper limit of 21 characters. Since the prefix consumes 6 characters, only 15 characters remain for the name you choose.
If the DBInstance name is longer than 15 characters, the generated resource names are silently truncated, while the HAProxy Service selectors still reference the un-truncated name. As a result, the HAProxy Service selector does not match the actual MySQL pods, and the MySQL cluster becomes unreachable through HAProxy.
Kubernetes cluster secret reference
To deploy the Cennso Database Instance to a Core Cluster, you must specify the reference to the Kubernetes secretOpens in a new tab so this cluster can be accessible. You can do this using the following configuration parameters:
Set spec.connectionSecretRef.name to the name of the Core Cluster where the Cennso Database Instance should be installed. The spec.connectionSecretRef.namespace configuration parameter defines the Kubernetes Namespace on the Management Cluster where the Kubernetes secret to access this Core Cluster is stored.
Image and chart configuration
You can use the following configuration parameters to specify the versions of the container image along with the secret to pull the image and Helm chart of the Cennso Database Instance:
Scheduling and placement configuration
The MySQL instances specified by the Cennso Database Instance CR are deployed in the Kubernetes namespace specified by the following configuration option:
The node where a MySQL instance runs depends on how its storage is configured, as described in the Storage configuration section.
MySQL cluster size
Important
The value of the spec.mysql.size parameter must not exceed the number of entries in spec.instances.
The Cennso Database extension allows you to deploy and manage database clusters consisting of multiple database instances. By default, the number of MySQL instances that run in the cluster equals the number of entries in the spec.instances parameter. Using the optional spec.mysql.size configuration option, you can change the number of instances. The most common use case is to scale down your cluster for maintenance operations, for example, restoring a database from backup. You can use this configuration option to scale down your cluster to zero nodes:
Scaling down does not remove the storage of the stopped instances. When you increase spec.mysql.size again, the instances reuse their existing storage.
Liveness, readiness, and startup probes configuration
Important
Since a MySQL instance can take a long time to get up and running after a restart, make sure that the startup probes are configured with a failureThreshold value high enough for the MySQL restore procedure.
You can use the following configuration parameters to specify the configuration for the liveness, readiness, and startup probes applied to the MySQL instance deployments:
For more information, see the official Kubernetes documentationOpens in a new tab.
Storage configuration
The storage configuration section allows you to specify the size and the storage classOpens in a new tab of the requested storage for a MySQL database instance:
The spec.storage.className refers to a StorageClass on the target Core Cluster. This can be a StorageClass that already exists there, or one of the storage classes created with spec.storage.classes of the DBOperator CR, as described in the Storage configuration section of the Cennso Database Operator document. If you plan to use an existing StorageClass, make sure that it exists on the target Core Cluster before you deploy the database instances.
These settings apply to all MySQL instances of the cluster. The source of each MySQL instance's volume is defined per instance in spec.instances or by the storage class from spec.storage.className. Read the next sections to get more information.
Volumes provided by the storage class
If you don't define spec.instances[].storage, the volume of each MySQL instance is requested with a PersistentVolumeClaim (PVC) created from the volume claim template of the MySQL StatefulSet. This PVC refers to the storage class specified in spec.storage.className. In this case, you can not directly specify nodes or paths in the Cennso Database Instance CR. Each MySQL instance runs on a node where the provisioner can provide its volume. Depending on the provisioner, this can be any node of the Core Cluster or only specific nodes. The MySQL instances must still be listed in spec.instances, each as an empty entry:
Node-local volumes
The spec.instances[].storage setting places a MySQL instance on a specific node and keeps its data in a specific directory on that node. Use it when the data must stay on the local disks of dedicated nodes, or when you need to know in advance on which node each MySQL instance runs.
For each entry with this setting, the Cennso Database Instance creates the following resources:
- Persistent Volume with the capacity specified in spec.storage.capacity for the given node and path
- Persistent Volume Claim bound to this volume
In such a case, the provisioner of the storage class specified in spec.storage.className does not create the volume. The name of the storage class is only assigned to the Persistent Volume and the Persistent Volume Claim. The Persistent Volume has a node affinity for the node specified in spec.instances[].storage.node, so the MySQL instance always runs on this node. See the configuration example:
Important
The directories specified in the spec.instances[].storage.path must exist on the nodes before you deploy the Cennso Database Instance. For more information, read the Deploy Cennso Database guide.
Data after deletion
The database data is kept when the Cennso Database Instance is deleted if spec.persistentVolumeReclaimPolicy was set to RetainOpens in a new tab in the database's Persistent Volume. A Cennso Database Instance created later with the same name and storage configuration starts with this data. To start with empty data, remove it first:
- Without spec.instances[].storage, delete the Persistent Volume Claims of the MySQL instances in the namespace of the MySQL cluster. If the storage class was created by the Cennso Database Operator, also remove the directories of the volumes on the nodes, as described in the Storage configuration section of the Cennso Database Operator document.
- With spec.instances[].storage, delete the content of the directories specified in spec.instances[].storage.path on the nodes.
TLS secret configuration
Using the following configuration option, you can configure the reference to the Kubernetes Secret which contains TLS certificates and keys used for the encrypted connections to the MySQL server:
This Kubernetes Secret must exist in the Core Cluster, in the same namespace where you deployed your MySQL instances.
By default, this value is an empty string, which means the TLS secret created by the Cennso Database Operator is used. In addition, you can specify the secret generated based on the XDBTLSCertificate. For more information, see the Cennso Database Certificate and Manage TLS certificates documents.
MySQL resources, server, and environment configuration
You can specify resourcesOpens in a new tab for MySQL instances using the following configuration options:
Both spec.mysql.resources.cpu and spec.mysql.resources.memory are set to the CPU/memory requests and limits.
Important
The value specified in the spec.mysql.resources.memory parameter is a base to calculate the size of innodb_buffer_pool_sizeOpens in a new tab, which configures the underlying database engine. The size of the buffer pool is set to 75% of the specified resources. To get a valid value, you must use only G or Gi quantity suffixOpens in a new tab.
To configure the MySQL server, use the following configuration option:
For more information about available configuration options, see the official MySQL documentationOpens in a new tab.
To improve memory management, you can enable jemallocOpens in a new tab allocator in MySQL servers. You can do this using the following configuration options:
By default, the jemalloc shared library is located at /lib64/libjemalloc.so.2 and is defined in the ldPreload parameter. The allocator settings are specified in mallocConf, which is by default set to background_thread:true,dirty_decay_ms:2000,muzzy_decay_ms:0,narenas:4,lg_tcache_max:14. For more information about these and other available jemalloc tunables, see the official documentationOpens in a new tab.
You can change both settings using the following configuration options:
In addition, you can use the spec.mysql.additionalEnvs configuration option to specify extra environment variables for MySQL server instances. For example:
Cloning database instances
Important
If you enable binary-donor with setting spec.binaryDonor.enabled to true, the CLONE is always disabled, even if you enable it by setting the configuration option described below.
When a new secondary replica is up and running, it clones data from the primary instance using the CLONEOpens in a new tab operation. To disable this behaviour, use the following configuration option:
SQL applied during role change
The Cennso Database extension lets you tune MySQL server settings based on the role of the instance. This covers the initial bootstrap, scale-out of new replicas, MySQL restarts, automatic failovers, and graceful takeovers. In every case, the matching SQL is re-applied so the server-side settings always reflect the pod's current role. The DBInstance CR exposes the following configuration options, which can contain a set of SQL commands executed during a role change:
The spec.mysql.roleChange.primarySQL is applied to the pod currently labelled as the primary. The spec.mysql.roleChange.replicaSQL is applied to every other pod.
Note
Each statement must be terminated by ;.
The default values prioritize replication throughput over durability. The primary flushes the binary log and InnoDB redo log on every transaction commit, while replicas leave both flush operations to the operating system. The MySQL event scheduler is enabled only on the primary, so scheduled events do not run twice during a failover.
Tip
Events created on a primary are replicated to replicas with the status REPLICA_SIDE_DISABLED. After a failover, the former replica that takes over as primary may not run those events even though its event scheduler is now ON. To activate them on the new primary, add the following SQL command to your spec.mysql.roleChange.primarySQL configuration:
Additional services and tools
In addition to the MySQL itself, the DBInstance CR controls the following components:
- HAProxy
- Orchestrator
- Backup
- Percona MySQL Toolkit
- Prometheus mysqld exporter
- Binary log donor server
The following sections provide information about the configuration of these tools and services.
Binary log donor server
Important
This section provides information only about the available configuration options for binary-donor. For the deployment details, see the Deploy Cennso Database deployment guide. For more information, see Enable binary-donor.
The Cennso Database extension provides a lightweight MySQL binary log server that enables zero data loss during MySQL failover. You can enable it using the following configuration options:
The binary-donor also replaces the deprecated spec.replicationSyncWaitTimeOnUpgrade configuration option of the DBOperator Custom Resource. A restarted database instance catches up with the primary from the exposed binary logs, so the database operator does not need to wait between the restarts of the database instances. For more information, see the Graceful upgrade section.
Each binary-donor instance should have assigned server-idOpens in a new tab. You can do it using the following configuration option:
This configuration option is optional and can be omitted. In this case, the unique server-id is assigned during deployment, starting from 65536.
You can specify the repository and container image tag for binary-donor using the following configuration options:
To specify Kubernetes resourcesOpens in a new tab for binary-donor, you can use the following configuration options:
You can apply additional labelsOpens in a new tab and annotationsOpens in a new tab to the binary-donor Kubernetes Deployment and Service resources:
The spec.binaryDonor.deploymentLabels are applied to both the Deployment and its Pod templates.
To change the log level of the log messages that binary-donor produces, you can use the following configuration:
The available log levels are:
debuginfowarnerror
HAProxy configuration
To connect to the database instances, you can enable and configure the deployment of the HAProxyOpens in a new tab service using the following configuration options:
The spec.haproxy.image configuration option defines the image of the HAProxy container itself, while the spec.haproxy.initImage configuration option defines the image of the init container that provisions the HAProxy configuration and the helper scripts.
You can specify resourcesOpens in a new tab for HAProxy using the following configuration options:
Both spec.haproxy.resources.cpu and spec.haproxy.resources.memory are set to the CPU/memory requests and limits. If an HAProxy container needs more CPU than the limit, Kubernetes throttles it. If it needs more memory than the limit, Kubernetes kills the container with the OOMKilled reason, and the client connections through this HAProxy pod are interrupted. Set the values according to the expected load on HAProxy. To see how much CPU and memory HAProxy uses, see the HAProxy CPU and memory usage section of the Grafana dashboard.
Note
The values are applied to each container of the HAProxy pod. Every HAProxy pod runs the HAProxy container and the sidecar that updates the HAProxy backends, so the requests and limits of the pod are twice the specified CPU and memory.
You can specify the Pod security contextOpens in a new tab, using the following configuration options:
HAProxy applies a set of options to each MySQL backend server. These options control the health check - a check for replication status and the value of the read_only status variable. This lets HAProxy detect a failed MySQL instance and stop routing traffic to it. By default, it is configured like this for each MySQL backend:
The default configuration means:
checkenables the health check for the MySQL instance.inter 10000runs a health check every10000milliseconds.rise 1marks the MySQL instance as available after1successful health check.fall 2marks the MySQL instance as unavailable after2consecutive failed health checks.weight 1gives the MySQL instance the same share of the traffic as the other instances with the same weight.
You can change some values of these configuration options using these parameters:
Each value has an allowed range. The API server rejects a claim with a value outside it:
Note
The health check option is always enabled, and you can not turn it off.
Using the spec.haproxy.serverOptions.additionalOptions configuration option, you can append further options to the ones above. For example:
Note
The spec.haproxy.serverOptions.additionalOptions configuration option can be up to 1024 characters long, and must not contain the check, no-check, inter, rise, fall, and weight options. HAProxy applies the value from the last occurrence of a repeated option, so these options override the values configured for other spec.haproxy.serverOptions configuration options.
For more information about the available options, see the official documentationOpens in a new tab.
In addition, you can specify annotationsOpens in a new tab for the HAProxy Kubernetes serviceOpens in a new tab using these parameters:
For each entry in spec.instances, the Cennso Database Instance also creates a Kubernetes service that targets the single HAProxy instance with the same number. Using the optional spec.instances[].externalIP configuration option, you can assign an external IP address to this service. The number of external IP addresses must not exceed the number of HAProxy instances specified in spec.haproxy.size:
Orchestrator configuration
To orchestrate the MySQL instances within a MySQL cluster, you can enable and configure the deployment of the MySQL OrchestratorOpens in a new tab service using the following configuration options:
In addition, you can use the spec.orchestrator.additionalEnvs configuration option to specify extra environment variables for the Orchestrator container. For example:
Backup configuration
To perform backups, you can deploy the Percona XtraBackupOpens in a new tab with resticOpens in a new tab client using the Cennso Database Instance CR. To configure the deployment of these components, use the following configuration options:
For more information about backups, see the Cennso Database Backup and Back up and restore documents.
Percona MySQL Toolkit configuration
The Cennso Database Instance CR provides deployment of the Percona ToolkitOpens in a new tab along with the MySQL database instances. You can configure it using the following configuration options:
Prometheus mysqld exporter configuration
The Cennso Database Instance CR allows deployment of the Prometheus mysqld exporterOpens in a new tab for monitoring the MySQL database clusters. You can enable it with:
For more information, see Enable metrics collector.