
Percona Server for MySQL is a free, fully compatible, enhanced, and open-source drop-in replacement for any MySQL database. By using the Percona Distribution for MySQL Operator in Kubernetes environments, you can ensure data availability for your MySQL database while simplifying the complex deployments using Kubernetes configuration files. This guide explains how to deploy, configure, and backup a high-availability MySQL cluster with Vultr Kubernetes Engine. Backups are stored separately on Vultr Object Storage with the ability to restore with point-in-time recovery.
Before you begin, you should:
kubectl and git in your machine.Install Percona Distribution for MySQL Operator version 1.10.0 using Kubectl:
Step 1: Download the source code for this guide.
Step 2: Deploy your database cluster using the following command:
The CR spec file for your database cluster is defined in the file 001_cr_minimal.yaml.
The 001_cr_minimal.yaml is designed specifically for Vultr Kubernetes Engine.
By default, this spec file creates a cluster named db-cluster with 03 pods for MySQL Instances and 03 HAProxy pods for high availability. A Vultr Block Storage are used as the data storage for each MySQL instance.
The results of running kubectl get pods -o wide are similar too:
Step 1: Get the root password to access the MySQL service under the secret named db-cluster-secrets.
The output should look as follows:
Get the base64 encoded password as root. It is MUVtTnBDVkdJeWI4cVlraGVY in this example case here.
Step 2: Decode the value for the root password using the following command:
Step 3: Create a pod in the Kubernetes cluster to access the MySQL service.
Step 4: Login using the mysql tool as follows (replace
Add the serviceType under haproxy in CR YAML spec to expose the MySQL Service for applications outside of Kubernetes
Install the provided 002_cr_load_balancer.yaml spec to enable load balancers. This command creates Vultr Load Balancers in your account.
This section shows how to manage backups and restores to have a good disaster recovery plan with a 3-2-1 backup strategy.
A 3-2-1 backup strategy means having at least three total copies of your data (one production data and two backup copies) on two different media and one offsite backup.
For the sake of simplicity, this guide takes advantage of the scheduled backup feature to automatically archive three copies of data:
Get the access id and access key of the Vultr Object Storage.
vultr-s3-secret.Here is the 003_vultr_s3_secrets.yaml file as an example.
Step 2: Save the secret to Kubernetes
Step 3: Create a bucket with the name db-cluster-backup in your Vultr Object Storage. This bucket is used to store the backup data in a later section.
Create another Vultr Object Storage or use any S3-compatible Object Storage.
offsite-s3-secretHere is the example spec, 004_offsite_s3_secrets.yaml
Step 2: Save the secret to Kubernetes
Step 3: Create a bucket with the name db-cluster-offsite-backup in your Object Storage. This bucket are used to store the backup data in a later section.
The file 005_cr_with_backup_s3.yaml contains a new backup section with the secrets in the previous step.
In the above spec, a scheduled backup runs every day and there are at most 10 copies of those in the storage. The point-in-time recovery feature is enabled to give you the ability to restore to any specific date and time.
Step 1: Make sure that the bucket, endpointUrl are correct and apply the changes with the following command:
The results of running kubectl get pods -o wide are similar too:
Step 2: Check the logs of the backup pod PITR with the following command. You need to change the pod name to your corresponding pod name.
The result shows that binary logs have been successfully written to S3. These are the backup for the Point-In-Time Recovery feature.
Step 1: Create a new spec file 006_manual_backup.yaml, to make a manual backup
Step 2: Run the command to perform the backup:
Step 3: Run the following command to see the backup progress:
The result should look similar to:
Succeeded, you can go to the Vultr Object Storage to browse for the files.Step 1: Create a pod to access the database. (replace
Step 2: Create a new database and table by running the following MYSQL commands
Step 3: Add a few rows to the database table
Step 4: Make sure that the binary logs are uploaded to Vultr Object Storage before deleting the database
Step 5: Drop the database for test purpose
Step 1: Disable PITR before doing any restore, even if the backup was not made with point-in-time recovery. Set the property spec.backup.pitr.enabled to false in CR YAML file.
Step 2: Apply the 007_cr_disable_pitr.yaml file using the following command:
Step 3: Prepare the restore spec file to restore to the time right after you drop the database. Here is my restore spec file 008_restore.yaml. You need to change the date-time to match your setup.
Step 4: Perform the recovery using the command:
Step 5: Run the following command to see the progress:
The result should look similar to:
Step 6: After the status changed to Succeeded, perform the query to check the database
Step 7: Enable the PITR feature by setting the spec.backup.pitr.enabled to true. Run the following command:
If you don’t see any changes under the status when running either kubectl get pxc-restore or kubectl get pxc-backup, try to reset the Percona Operator pod as follows:
Get the pod name of Percona Operator
Delete the pod. (Replace
Create a pod to run the sysbench benchmark. Replace
Create a database named sbtest
Prepare data tables
Perform Read-Write test
Perform Read-only test
Perform Write-only test
Perform Select-Random-Points test
Clean up the test data
Uninstall everything in this guide as follows:
Delete the cluster:
Delete the PXC backup
Delete the PXC restore
Delete the Persistent Volume Claim
Delete the secrets
Delete Percona Distribution for MySQL Operator
Delete files in your Object Storage
0 Comments
Be the first to comment and share your perspective with the community.