Topologies
Operations
Backup And Restores
Custom Secret
Monitoring
This guide demonstrates how to deploy a MySQL cluster in KubeBlocks with a custom root password stored in a Kubernetes Secret.
Before proceeding, ensure the following:
kubectl create ns demo
Expected Output:
namespace/demo created
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.
The custom root password is stored in a Kubernetes Secret. Create the Secret by applying the following YAML:
kubectl apply -f - <<EOF
apiVersion: v1
data:
password: Y3VzdG9tcGFzc3dvcmQ= # custompassword
username: cm9vdA== #root
immutable: true
kind: Secret
metadata:
name: custom-mysql-root-secret
namespace: demo
EOF
echo -n "custompassword" | base64
).Apply the following manifest to deploy the MySQL cluster, referencing the Secret created in Step 1 for the root account:
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: example-mysql-cluster
namespace: demo
spec:
clusterDef: mysql
topology: semisync
terminationPolicy: Delete
componentSpecs:
- name: mysql
serviceVersion: 8.0.35
replicas: 2
systemAccounts:
- name: root
secretRef:
name: custom-mysql-root-secret
namespace: demo
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
EOF
Once the cluster is deployed, check its status by running the following command:
kubectl get cluster example-mysql-cluster -n demo -w
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
example-mysql-cluster mysql Delete Creating 19s
example-mysql-cluster mysql Delete Running 1m
Wait until the STATUS changes to 'Running'.
KubeBlocks automatically creates a secret containing the MySQL root credentials. Retrieve the credentials with the following commands:
kubectl get secrets -n demo example-mysql-cluster-mysql-account-root -o jsonpath='{.data.username}' | base64 -d
root
kubectl get secrets -n demo example-mysql-cluster-mysql-account-root -o jsonpath='{.data.password}' | base64 -d
custompassword
To connect to the cluster's primary node, use the MySQL client with the custom password:
kubectl exec -it -n demo example-mysql-cluster-mysql-0 -c mysql -- mysql -h example-mysql-cluster-mysql.demo.svc.cluster.local -uroot -pcustompassword
To remove all created resources, delete the MySQL cluster along with its namespace:
kubectl delete cluster example-mysql-cluster -n demo
kubectl delete secret custom-mysql-root-secret -n demo
kubectl delete ns demo
In this guide, you:
Using Kubernetes Secrets ensures secure credential management for your MySQL clusters, while KubeBlocks simplifies the deployment and management process.