This topic describes how to create and delete MySQL instances.
Before you can create or delete MySQL instances, you must have:
The Kubernetes Command Line Interface (kubectl) installed. For more information, see the Kubernetes documentation.
Full admin access to all Kubernetes resources in your developer namespace.
For information about Roles and RoleBindings that your Kubernetes cluster admin needs to create, see the Kubernetes documentation.
The URL and credentials to access the registry that stores the Tanzu MySQL for Kubernetes images. This can be the VMware Tanzu Network registry or the private registry configured for your environment. If you do not have access to the registry credentials, contact your Kubernetes admin to have these set up for you in your namespace.
The VMware Tanzu™ SQL with MySQL for Kubernetes deployment templates. See Download the Deployment Templates.
In order to create VMware Tanzu™ SQL with MySQL for Kubernetes instances, you must first download the deployment templates from Tanzu Network. You use these templates to create configuration files that specify the Tanzu MySQL for Kubernetes resources that you wish to create.
Note: You only need to download the templates once (before you first create a MySQL instance).
To access the templates:
Log in to VMware Tanzu Network.
Visit the VMware Tanzu™ SQL with MySQL for Kubernetes product page.
Click VMware Tanzu SQL with MySQL for Kubernetes v1.1.0. This will download a .tgz archive file to your local machine.
Expand the downloaded .tgz file. Open the directory
tanzu-mysql-for-kubernetes-1.1.0. The templates are located in the
The templates include the following:
backup.yaml(for the MySQLBackup resource)
backuplocation.yaml(for the MySQLBackupLocation resource)
backupschedule.yaml(for the MySQLBackupSchedule resource)
mysql.yaml(for the MySQL resource; this template is used to create MySQL instances)
restore.yaml(for the MySQLRestore resource)
tls-secret.yaml(for a TLS Secret)
You do not need to download the Artifact References from the Tanzu MySQL for Kubernetes product page.
To create a MySQL instance:
Target the namespace where you want to create the MySQL instance:
kubectl config set-context --current --namespace=DEVELOPMENT-NAMESPACE
DEVELOPMENT-NAMESPACE is the namespace in which you want to create the instance.
kubectl config set-context --current --namespace=my-namespace
From your namespace, Kubernetes must be able to access the registry that stores the Tanzu MySQL for Kubernetes images. To allow this, create an imagePullSecret by running:
kubectl --namespace=DEVELOPMENT-NAMESPACE create secret docker-registry tanzu-mysql-image-registry --docker-server=REGISTRY-SERVER-URL --docker-username=DOCKER-USERNAME --docker-password=DOCKER-PASSWORD
DEVELOPMENT-NAMESPACEis the namespace in which you want to create the instance
REGISTRY-SERVER-URLis the VMware Tanzu Network registry or the private registry configured for your environment
DOCKER-PASSWORDare the credentials used to pull images from the registry.
kubectl create secret --namespace=my-namespace \ docker-registry tanzu-mysql-image-registry \ --docker-server=https://registry.tanzu.vmware.com/ \ --docker-username=sample-username \ --docker-password=sample-password secret/tanzu-mysql-image-registry created
mysql.yaml deployment template that you downloaded in the TGZ file from VMware Tanzu Network. For how to download deployment templates, see Download the Deployment Templates.
Create a copy of the
mysql.yaml file and give it a unique name.
cp ~/Downloads/tanzu-mysql-deployment-templates-1.0.0/samples/mysql.yaml testdb.yaml
Edit the file and customize the instance according to your requirements.
You may customize your Tanzu MySQL instance version, instance resources, instance storage class, high availability, node affinity and tolerations, PVC retention policy, service type (ClusterIP or LoadBalancer), and TLS secret. For more details on all the properties that you can set for the MySQL resource, see Property Reference for the MySQL Resource.
When you create a MySQL instance, the MySQL Operator also creates PVCs. The PVCs are attached to the instance and contain the data for the MySQL database. Single-node instances have one PVC, and high-availability (HA) instances have three. The PVC name contains the instance name and the MySQL Pod number. The PVC name is of the form
mysql-data-INSTANCE-NAME-N, for example
Deploy a MySQL instance to Kubernetes by running:
kubectl -n DEVELOPMENT-NAMESPACE apply -f FILENAME
FILENAME is the name of the configuration file you created in Step 4 above.
kubectl -n my-namespace apply -f testdb.yaml
Verify that the instance was created successfully by running:
kubectl -n DEVELOPMENT-NAMESPACE get mysql INSTANCE-NAME
INSTANCE-NAME is the value that you configured for
metadata.name in your file
kubectl -n my-namespace get mysql mysql-sample
NAME READY STATUS AGE mysql-sample true Running 2m17s
By default, the MySQL servers created by Tanzu Operator 1.2.0 (and later) use TLS certificates provided by the cert-manager
ClusterIssuer, using a self-signed certificate authority (CA). For more information on TLS and how to configure custom a
ClusterIssuer, see Configuring TLS for MySQL Instances.
This section provides some conceptual information about deleting an instance, and the procedure for how to delete an instance.
There are two steps to deleting an instance. The first step is to delete the instance itself, and the second step is to delete the PVCs.
There are situations where you want to delete the instance but not delete the PVC. For example, in a test environment, you might delete the instance to save costs but keep the PVC storing the data. If you later create a new instance with the same name as the deleted instance, the old PVCs automatically reattach to the new instance and you have access to your data again.
Note: If you delete the Pod or the StatefulSet associated with the MySQL resource, the Operator re-creates it for you. To permanently delete the instance, you need to delete the MySQL resource, as described in step 1 below.
To delete a MySQL instance:
Delete the MySQL instance by running:
kubectl -n DEVELOPMENT-NAMESPACE delete mysql INSTANCE-NAME
DEVELOPMENT-NAMESPACEis the namespace where you created the instance.
INSTANCE-NAMEis the name of the instance you want to delete.
kubectl -n my-namespace delete mysql mysql-sample
my-namespace "mysql-sample" deleted
(Optional) Delete the PVCs by running:
Warning: This command is destructive. When you destroy your PVCs, you delete all data associated with your Tanzu MySQL for Kubernetes database.
kubectl delete pvc -l app.kubernetes.io/instance=INSTANCE-NAME
INSTANCE-NAME is the name of the MySQL instance that you deleted above.
kubectl delete pvc -l app.kubernetes.io/instance=mysql-sample
persistentvolumeclaim "mysql-data-mysql-sample-0" deleted
Note: For HA MySQL instances, the command deletes all three PVCs associated with the MySQL instance.