> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cennso-db/1.1/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cennso-db/1.1/cennso-db-instance.md).

# Cennso Database Instance

The `percona-db-instance` composition implements the Cennso DB Instance Composite Resource Definition (XRD).

For further details, see the [Cennso DB Instance CRD definition](https://docs.cennso.com/cennso/cennso-db/1.1/technical-reference/configurations/cennso-db/xdbinstance_definition.md)

## Deploy Cennso DB Instance

1. Ensure you have Cennso DB Operator installed on your Core Cluster. You can find the installation instructions in the [Cennso DB Operator documentation](https://docs.cennso.com/cennso/cennso-db/1.1/cennso-db-operator.md).

2. Ensure the operator watches the namespace where you want to deploy the Cennso DB Instance.

3. Ensure the local-path-provisioner on your Core Cluster is configured to use the paths you want to use for the storage on a specified nodes.

   ```bash
   kubectl -n local-path-provisioner get cm local-path-config -oyaml
   ```

   The output should be similar to the following, where you can see the paths for the storage on the specified nodes:

   ```yaml
   apiVersion: v1
   data:
      config.json: |-
         {
            "nodePathMap": [
               {
                  "node": "DEFAULT_PATH_FOR_NON_LISTED_NODES",
                  "paths": [
                     "/opt/local-path-provisioner"
                  ]
               },
               {
                  "node":"mynode1",
                  "paths":["/opt/local-path-provisioner/mystorage"]
               },
               {
                  "node":"mynode2",
                  "paths":["/opt/local-path-provisioner/mystorage"]
               }
            ]
         }
   ...
   ```

4. To configure local-path-provisioner, you can modify your Core Cluster manifest on the Management Cluster to include the necessary paths and nodes. For further details, see the [Core Cluster reference](https://docs.cennso.com/cennso/cennso/main/technical-reference/crds/corecluster_definition.md).

   Ensure the paths for the storage are created on the nodes in your Core Cluster. You need to create the directories on the specified nodes where the storage will be provisioned. You can use `kubectl debug` to access the nodes and create the directories.

   ```bash
   kubectl debug node/mynode1 -it --image=ubuntu
   mkdir -p /host/opt/local-path-provisioner/mystorage/instance0
   exit

   kubectl debug node/mynode2 -it --image=ubuntu
   mkdir -p /host/opt/local-path-provisioner/mystorage/instance1
   exit
   ```

5. Prepare the `DBInstance` Custom Resource (CR) to deploy the Cennso DB Instance in your cluster. This CR defines the connection to the Core Cluster, the storage configuration, and the MySQL instance settings. For example:

   ```yaml
   apiVersion: db.contrib.cennso.com/v1alpha1
   kind: DBInstance
   metadata:
      name: mydb
      namespace: cennso-infra
   spec:
      connectionSecretRef:
         name: mycorecluster
         namespace: cennso-infra
      namespace: mydbnamespace
      storage:
         capacity: 20Gi
         className: mystorage
      instances:
         0:
            storage:
               node: mynode1
               path: /opt/local-path-provisioner/mystorage/instance0
         1:
            storage:
               node: mynode2
               path: /opt/local-path-provisioner/mystorage/instance1
   ```

   Keep the DB Instance CR name short so the names of the created Persistent Volume Claims do not exceed the Kubernetes limit of 63 characters. The names of the Persistent Volume Claims (PVCs) are derived from the DB Instance name, namespace, and the instance number, so a shorter name helps avoid issues with PVC names exceeding this limit.

   For further details, see the [Cennso DB Instance CRD definition](https://docs.cennso.com/cennso/cennso-db/1.1/technical-reference/configurations/cennso-db/xdbinstance_definition.md).

6. Apply the prepared CR to your Management Cluster:

   ```bash
   kubectl apply -f mydb.yaml
   ```

## Update Cennso DB Instance

It's strongly recommended to set the `spec.compositionUpdatePolicy` to `Manual` to avoid automatic updates of the DB Instance composition. This allows you to control when the updates are applied and ensures that the database instance is not disrupted during the update process.

To update the Cennso DB Instance, modify the CR with the desired `spec.compositionRevisionRef.name` and apply the changes.

When upgrading the Cennso DB Instance under load, ensure your Cennso DB Operator has an adequate `spec.replicationSyncWaitTimeOnUpgrade` value configured. To improve the performance of the upgrade process, you can set the `spec.mysql.cloneRequiredOnAsyncCluster` to `false`. This will skip the cloning process during the upgrade.

Only patch release upgrades are supported for the Cennso DB Instance. Major and minor version upgrades are not supported and may lead to issues with the database instance. If you need to upgrade to a new major or minor version, you should create a new Cennso DB Instance with the desired version and migrate your data.
