Create a MySQL Cluster With Custom Password Generation Policy on KubeBlocks
This guide explains how to deploy a MySQL cluster in KubeBlocks with a custom password generation policy for the root user. By defining specific password rules, you can ensure strong, secure credentials for your cluster.
Prerequisites
Before proceeding, ensure the following:
Environment Setup:
A Kubernetes cluster is up and running.
The kubectl CLI tool is configured to communicate with your cluster.
Namespace Preparation: To keep resources isolated, create a dedicated namespace for this tutorial:
kubectl create ns demo
namespace/demo created
Deploying the MySQL Semi-Synchronous Cluster
KubeBlocks uses a declarative approach for managing MySQL clusters. Below is an example configuration for deploying a MySQL cluster with 2 nodes (1 primary, 1 replicas) in semi-synchronous mode and a custom root password that adheres to a specific pattern.
kubectlapply-f-<<EOFapiVersion:apps.kubeblocks.io/v1kind:Clustermetadata:name:example-mysql-clusternamespace:demospec:clusterDef:mysqltopology:semisyncterminationPolicy:DeletecomponentSpecs:-name:mysqlserviceVersion:8.0.35replicas:2systemAccounts:-name:rootpasswordConfig:length:20# Password length: 20 charactersnumDigits:4# At least 4 digitsnumSymbols:4# At least 4 symbolsletterCase:MixedCases# Uppercase and lowercase lettersresources:limits:cpu:'0.5'memory:0.5Girequests:cpu:'0.5'memory:0.5GivolumeClaimTemplates:-name:dataspec:storageClassName:""accessModes:-ReadWriteOnceresources:requests:storage:20GiEOF
Key Features of the Password Policy:
Length: 20 characters.
Composition:
At least 4 digits.
At least 4 symbols.
Mixed uppercase and lowercase letters.
This ensures the generated password is strong and secure.
Verifying the Deployment
Once the cluster is deployed, monitor its status:
kubectl get cluster example-mysql-cluster -n demo -w
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
example-mysql-cluster mysql Delete Creating 10s
example-mysql-cluster mysql Delete Running 1m
Wait until the STATUS changes to Running.
Retrieving the Password
KubeBlocks automatically creates a secret containing the MySQL root credentials. Retrieve the credentials with the following commands:
Configured and deployed a MySQL cluster with a custom password generation policy using KubeBlocks.
Verified the deployment and retrieved the generated root password.
Connected to the MySQL cluster using the secure, auto-generated password.
This approach simplifies password management while maintaining high-security standards for your database deployments.