Binding a TAS Application to a MySQL Instance

Page last updated:

This topic demonstrates how to connect an application running on VMware Tanzu Application Service for VMs (TAS) to a VMware Tanzu™ SQL with MySQL for Kubernetes instance.

Prerequisites

Before you can connect an application running on TAS to a Tanzu MySQL for Kubernetes instance, you must have:

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

  • A Tanzu MySQL for Kubernetes instance installed on a Kubernetes cluster that supports a form of external ingress, for example a LoadBalancer. For more details see Creating and Deleting MySQL Instances.

  • An application that is deployed to TAS and can access the Kubernetes cluster ingress points.

Binding an Application

To bind a MySQL instance to an application running on TAS:

  1. Deploy an instance of VMware Tanzu™ SQL with MySQL for Kubernetes that uses a public ingress method, such as LoadBalancer.
  2. Enable TLS for the instance, following the instructions in Configuring TLS for MySQL Instances.
  3. Create a database and a privileged MySQL user for the application, following the procedure Create a Database and Privileged MySQL User for the App.
  4. Set the environment variables for your newly created user and for the load balancer hostname:

    export HOSTNAME=$(kubectl get service mysql-sample  -o 'jsonpath={.status.loadBalancer.ingress[].ip}')
    export USER=bn_wordpress
    export PASSWORD=hunter2
    export DATABASE=for_my_app
    
  5. Create a credentials hash for a TAS user-provided service configuration:

    cf create-user-provided-service k8s-tanzu-sql -p "{\"uri\":\"mysql://$USER:$PASSWORD@$HOSTNAME:3306/$DATABASE?reconnect=true&sslMode=required&ssl_mode=required\"}"
    

If autoconnect is supported by the applicatioin buildpack, as is common with data services, the application will automatically connect to the database instance. If the buildpack does not support autoconnect, you will need to manually use the uri service credentials to connect the application to the database instance.

Troubleshooting

This procedure, including autowiring, was validated with a Spring Boot application. Autowiring did not work with a Ruby on Rails application, because the version of the MariaDB client library in the Cloud Foundry cflinuxfs3 stack does not support sslMode.

  • If your application cannot make SSL connections, start by properly consuming the connection information components and making a manual connection from the application.
  • Some techniques for connecting non-Spring applications are provided in the Activate TLS for Non-Spring Apps section of the MySQL for VMs documentation. The credentials hash created in the Binding an Application procedure above does not include individual components of connection information, such as username and hostname, but you can derive these components by parsing the uri in the hash.
  • As a last resort, you can disable TLS on the MySQL instance and remove the ssl_mode and sslMode parameters from the credentials hash.