Connecting an App to the 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 explains how you, as a developer, connect an app to your TanzuMySQL instance.

About Binding Apps to a TanzuMySQL Instance

After you have created a TanzuMySQL instance, the next task is to bind it to your app so that your app can access the database.

You do this by obtaining the password for the root database user and the IP address for the TanzuMySQL instance and then adding these connection parameters to the app environment variables.

Prerequisites

Before you bind an app to a TanzuMySQL instance, you must have:

  • The Kubernetes Command Line Interface (kubectl) installed: For more information, see the Kubernetes documentation.

  • Permission to read Kubernetes secrets in your target namespace: For information about Roles and RoleBindings that your Kubernetes cluster admin needs to create to grant permissions, see the Kubernetes documentation.

    Note: To avoid Kubernetes permissions issues, VMware recommends that developers have admin access to their target namespace.

  • A TanzuMySQL instance running in the same Kubernetes cluster as the app: This is required. The ServiceType is ClusterIP. However, instances can be in a different namespace from the app.
    For how to create an instance, see Creating and Deleting a TanzuMySQL Instance.
    For information about the ClusterIP ServiceType, see the Kubernetes documentation.

Retrieve Connection Parameters for the TanzuMySQL Instance

To connect the app to the database, you provide the app with:

  • The root username and password for the database
  • The IP address for the TanzuMySQL instance

This procedure describes how to find these connection parameters.

To retrieve connection parameters:

  1. Obtain the password for the root user of the database by running:

    kubectl get secret INSTANCE-NAME-credentials -o jsonpath='{.data.rootPassword}' | base64 -D
    

    Where INSTANCE-NAME is the name of the TanzuMySQL instance.

    For example:

    $ kubectl get secret tanzumysql-sample-credentials \
      -o jsonpath='{.data.rootPassword}' | base64 -D
    examplepassword
    
  2. Record the password string, for example, examplepassword. You need it to complete the Connect your App to the MySQL Database below.

  3. Obtain the IP address of the TanzuMySQL instance by running:

    kubectl get service INSTANCE-NAME
    

    For example:

    $ kubectl get service tanzumysql-sample
    
    → kubectl get service tanzumysql-sample
    NAME                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
    tanzumysql-sample   ClusterIP   10.110.144.49           3306/TCP,33060/TCP   5d22h
    
  4. Record the value of the CLUSTER-IP, for example, 10.110.144.49. You need it to complete the Connect your App to the MySQL Database below.

Connect your App to the MySQL Database

To connect your app to the MySQL database on the TanzuMySQL instance:

  1. Manually configure the app environment variables with the connection parameters that you recorded above.

  2. Apply these changes to establish a connection to the database.