For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

You are reading CENNSO Database 1.1, an older release. The newest release is 1.5. Go to 1.5

Accidental deletion of a DB Instance composition

This document explains how to handle the accidental deletion of a DB Instance composition.

Each DB Instance causes the DB Operator to spin up N dedicated MySQL replicas, with one considered the primary. When the DB Instance object is deleted, the DB Operator deletes all Kubernetes objects related to the deleted DB Instance, such as Stateful Sets, Services, Deployments, etc. The only entities that are not deleted are Persistent Volumes which contain the database data.

When a DB Instance is bootstrapped, a set of management users along with matching credentials are created and stored within the database:

yaml

When the DB Instance is deleted, the Kubernetes secret (like the one mentioned above) is also deleted. However, the users and their passwords stored in that secret will still remain in the database, since the Persistent Volumes are not removed.

When you recreate the DB Instance, DB Operator creates a new Kubernetes secret and tries to create the users and the passwords in the DB Instance upon bootstrap. This fails because the intended users already exist in the database. A common symptom is the following error message in the readiness probe:

text

There are two ways to recover from this situation:

  • Delete the database files from the disk, let the DB Instance bootstrap, then use a backup to restore the data files.
  • Overwrite the existing passwords during the DB Instance bootstrap.

The best option depends on factors such as time constraints, backup availability, and the ability to restore from the backup.

The second recovery option is described below. Recovery using an available backup is not covered in this document.

Overwrite the existing passwords during the DB Instance bootstrap

  1. Patch the StatefulSet template of the DB Instance to allow access to the mysql container. Then, remove all lifecycle-related helpers from the mysql container configuration, including:
  • lifecycle

  • livenessProbe

  • readinessProbe

  • startupProbe

    To apply this, run the following command:

    bash

    Then, update the command field of the mysql container to keep it running without starting the actual database process:

    bash

    Finally, remove the xtrabackup and heartbeat containers:

    bash
  1. Delete all pods of the affected DB Instance. Kubernetes will re-create the pods in their patched version.

  2. Attach to the mysql container:

    bash
  3. Create a file with recovery script called /tmp/recovery.sh:

    bash

    The script resets internal MySQL user passwords directly within the container. Since the mysql process is not running (due to the overridden command), this allows you to enter the container safely and manually start MySQL with controlled conditions.

    The /tmp/recovery.sh script:

    • Loads user passwords securely from environment variables or mounted secrets.
    • Uses these values to update MySQL internal user accounts with new passwords.
    • Ensures MySQL permissions are refreshed using FLUSH PRIVILEGES.
  4. Run the /tmp/recovery.sh script:

    bash

    Once the log shows a success, send a TERM signalOpens in a new tab to the mysqld PID to stop the server:

    bash

Note

Repeat steps 3, 4, and 5 for each MySQL pod in the affected DB Instance.

  1. Set the replica parameter of the PerconaServerMySQL Kubernetes resource for the affected DB Instance to 0.

  2. Delete the StatefulSet of the affected DB Instance. Once the patched StatefulSet and its related resources are removed (Persistent Volumes are preserved), the operator will recreate a new one using the original configuration.

  3. Set the replica parameter of the PerconaServerMySQL Kubernetes resource for the affected DB Instance back to the original production value (usually 2). The DB Operator monitoring this resource will detect the change and recreate the StatefulSet with the default configuration.

At this point, the credentials stored in the database should match those in the corresponding Kubernetes Secret, allowing all components to start functioning correctly.