Creating and Deleting a TanzuMySQL Instance
Warning: VMware Tanzu™ SQL with MySQL for Kubernetes is currently in beta and is intended for evaluation and test purposes only. Do not use this product in a production environment. If you discover any bugs, contact Support.
Page last updated:
This topic describes how you, as a developer, deploy and delete TanzuMySQL instances.
Before you can create or delete TanzuMySQL 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.
To create a TanzuMySQL instance:
Target the namespace where you want to create the TanzuMySQL instance:
kubectl config set-context --current --namespace=DEVELOPMENT-NAMESPACE
DEVELOPMENT-NAMESPACEis 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.pivotal.io/ \ --docker-username=sample-username \ --docker-password=sample-password secret/tanzu-mysql-image-registry created
tanzumysql.yamlfile. You can use the template below:
apiVersion: mysql.tanzu.vmware.com/v1alpha1 kind: TanzuMySQL metadata: name: tanzumysql-sample spec: storageSize: 1Gi imagePullSecret: tanzu-mysql-image-registry #### Set the storage class name to change storage class of the PVC associated with this resource # storageClassName: standard #### Examples to set resource limit/request for mysql/backups containers. # resources: #### This is the container running the mysql server. # mysql: # limits: # cpu: 3 # memory: 800Mi # requests: # cpu: 2 # memory: 500Mi #### This is the sidecar container that takes a backup and streams to the storage backend. # backups: # limits: # cpu: 2 # memory: 500Mi # requests: # cpu: 1 # memory: 200Mi
tanzumysql.yamlfile. For an explanation of the properties that you can set in this file, see Property Reference for tanzumysql.yml.
Deploy a TanzuMySQL instance to Kubernetes by running:
kubectl -n DEVELOPMENT-NAMESPACE apply -f tanzumysql.yaml
$ kubectl -n my-namespace apply -f tanzumysql.yaml tanzumysql.mysql.tanzu.vmware.com/tanzumysql-sample created
Verify that the instance was created successfully by running:
kubectl get tanzumysql INSTANCE-NAME
INSTANCE-NAMEis the value that you configured for
$ kubectl get tanzumysql tanzumysql-sample NAME READY STATUS AGE tanzumysql-sample true Running 2m17s
This section provides some conceptual information about persistent volume claims (PVCs) and deleting an instance. It also provides the procedure for how to delete an instance.
When you create a TanzuMySQL instance, the Tanzu MySQL operator also creates a persistent volume claim (PVC). This PVC is attached to the instance and contains the data for the MySQL database.
The PVC name contains the instance name and the TanzuMySQL Pod number.
Currently only one Pod is allowed per instance, so the PVC name is of the form
Currently only one Pod is allowed per instance, so
N is always
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 PVC.
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 PVC automatically reattaches to the new instance and you have access to your data again.
Note: If you delete the Pod or the StatefulSet associated
with the Tanzu MySQL for Kubernetes resource,
a Tanzu MySQL for Kubernetes controller re-creates it for you.
To permanently delete the instance, you need to delete the
as described in step 1 below.
To delete a TanzuMySQL instance:
Delete the TanzuMySQL instance by running:
kubectl -n DEVELOPMENT-NAMESPACE delete tanzumysql 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 tanzumysql tanzumysql-sample my-namespace "tanzumysql-sample" deleted
(Optional) Delete the Persistent Volume Claim (PVC).
Warning: This is a destructive action. If you destroy your PVC, you delete all data associated with your Tanzu MySQL for Kubernetes database.
Review your PVCs by running:
kubectl get pvc
$ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mysql-data-tanzumysql-sample-0 Bound pvc-3262e841-c4aa-4aa4-b53a-68cd3078f806 1Gi RWO standard 7d1h mysql-data-another-sample-0 Bound pvc-87c8a3a9-263b-46e6-8acb-ed474434fd24 1Gi RWO standard 6d21h
Identify the names of the PVCs that correspond to the name of the instance you deleted above.
Delete the PVC associated with each TanzuMySQL Pod by running, for each Pod:
kubectl delete pvc mysql-data-INSTANCE-NAME-N
INSTANCE-NAMEis the name of the TanzuMySQL instance that you deleted above.
Nis the index of each Pod in the TanzuMySQL instance.
$ kubectl delete pvc mysql-data-tanzumysql-sample-0 persistentvolumeclaim "mysql-data-tanzumysql-sample-0" deleted