Using a9s MySQL for PCF

This topic describes how to use a9s MySQL for Pivotal Cloud Foundry (PCF) after it has been successfully installed. For more information, see the Installing and Configuring a9s MySQL for PCF topic.

Using a9s MySQL

This topic describes how to use a9s MySQL .

Use a9s MySQL with an Application

To use a9s MySQL with an application, create a service instance and bind the service instance to your app. For more information about managing service instances, see Managing Service Instances with the cf CLI.

View the a9s MySQL Service

After the service is installed, you can see the a9s-mysql and its service plans appear in your CF marketplace. Run cf marketplace to see the service listing: bash $ cf marketplace Getting services from marketplace in org test / space test as admin... OK service plans description a9s-mysql mysql-single-small, mysql-cluster-small, This is the anynines MySQL service. mysql-single-big, mysql-cluster-big

Create a Service Instance

To provision a MySQL database, run cf create-service.

$ cf create-service a9s-mysql mysql-single-small my-mysql-service

Depending on your infrastructure and service broker utilization, it may take several minutes to create the service instance.

Run cf services to view the creation status. This command displays a list of all your service instances. To view the status of a specific service instance, run cf service NAME-OF-YOUR-SERVICE.

Bind an Application to a Service Instance

After your database is created, run cf bind-service to bind the service to your application:

$ cf bind-service a9s-mysql-app my-mysql-service

Restage or Restart Your Application

To enable your application to access the service instance, run cf restage or cf restart to restage or restart your application.

Obtain Service Instance Access Credentials

After a service instance is bound to an application, the credentials of your MySQL database are stored in the environment variables of the application. Run cf env APP-NAME to display the environment variables.

You can find the credentials in the VCAP_SERVICES key.

$ cf env a9s-mysql-app
Getting env variables for app a9s-mysql-app in org test / space test as admin...
OK

System-Provided:
{
 "VCAP_SERVICES": {
  "a9s-mysql": [
   {
     "credentials": {
      "dns_servers": [
       "10.0.4.13",
       "10.0.5.5",
       "10.0.6.5"
      ],
      "host": "d566e59.service.dc1.a9s-mysql-consul",
      "host_ip": "10.0.10.4",
      "host_ips": [
       "10.0.8.4",
       "10.0.9.4",
       "10.0.10.4"
      ],
      "hosts": [
       "d566e59-mysql-0.node.dc1.a9s-mysql-consul",
       "d566e59-mysql-1.node.dc1.a9s-mysql-consul",
       "d566e59-mysql-2.node.dc1.a9s-mysql-consul"
      ],
      "name": "d566e59",
      "password": "a9s-password",
      "port": 3306,
      "uri": "mysql://a9s-brk-usr:a9s-password@d566e59.service.dc1.a9s-mysql-consul:3306/d566e59",
      "username": "a9s-brk-usr"
     },
     "instance_name": "mymysql",
     "label": "a9s-mysql101",
     "name": "mymysql",
     "plan": "mysql-cluster-small",
     "provider": null,
     "syslog_drain_url": null,
     "tags": [
      "sql",
      "database",
      "object-relational",
      "consistent"
    ]
   }
  ]
 }
}
...

You can use the host_ips, username and password values to connect to your database with a MySQL client.

a9s MySQL for PCF comes with its own Consul cluster to provide hostname resolving. When your DNS is configured to resolve the a9s MySQL for PCF service instance domains you can make use of hosts or uri. For more information see Name Resolving With Consul.

Delete an a9s MySql Service Instance

WARNING: Before deleting a service instance, you must back up data stored in your database. This operation cannot be undone and all the data is lost when the service is deleted.

Before you can delete a service instance, you must unbind it from all apps.

List Available Services

Run cf services to list your available services.

$ cf services

Getting services in org test / space test as admin...
OK

name               service     plan                 bound apps      last operation
my-mysql-service   a9s-mysql   mysql-single-small   a9s-mysql-app   create succeeded

This example shows that my-mysql-service is bound to the a9s-mysql-app application.

Unbind a Service Instance

Run cf unbind-service to unbind the service from your application.

$ cf unbind-service a9s-mysql-app my-mysql-service

Delete a Service Instance

After unbinding the service, it is no longer bound to an application. Run cf delete-service to delete the service:

$ cf delete-service my-mysql-service

It may take several minutes to delete the service. Deleting a service deprovisions the corresponding infrastructure resources. Run the cf services command to view the deletion status.

Upgrade the Service Instance to Another Service Plan

Once created, you can upgrade your service instance to another, larger service plan. A larger service plan provides more CPU, RAM and storage. For more information, see the Update a Service Instance of the Managing Service Instances with the cf CLI topic.

$ cf update-service my-mysql-service -p a-bigger-plan

Here are the plans you can upgrade to, depending on the one you are currently using:

Base Plan Target Plan
mysql-single-small mysql-single-medium
mysql-single-big
mysql-cluster-small
mysql-cluster-medium
mysql-cluster-big
mysql-single-medium mysql-single-big
mysql-cluster-medium
mysql-cluster-big
mysql-single-big mysql-cluster-big
mysql-cluster-small mysql-cluster-medium
mysql-cluster-big
mysql-cluster-medium mysql-cluster-big

Add a Graphite Endpoint

If you want to monitor your service with Graphite, you can set an endpoint to where to information will be sent with the cf update-service command. This command expects the -c flag and a JSON string containing the graphite and metrics_prefix keys. Depending on your graphite provider, the metrics_prefix might require that each metric must start with an API key in their name. You can also change the interval within the data is send to the endpoint. To do this, modify interval; the default is 10s.

$ cf update-service my-mysql-service -c '{ "graphite": ["yourspace.your-graphite-endpoint.com:12345"], "metrics_prefix": "your-api-key.my-cluster-mysql", "interval": "5"}'

Add a Syslog Endpoint

The cf update-service command used with the -c flag can let you stream your syslog to a third-party service. In this case, the command expects a JSON string containing the syslog key. You can also change the interval for the syslog with the same key than for the graphite endpoint interval.

$ cf update-service my-mysql-service -c '{ "syslog": ["logs4.your-syslog-endpoint.com:54321"], "interval": "5" }'

Cloud Foundry Application Security Groups

This topic describes how to check whether a security group was created.

Each a9s Data Service will automatically create and update Cloud Foundry security groups in order to protected service instances to be accessed by applications not running in the same Cloud Foundry applications space. To get a better understanding about Security Groups you can have a look on the Understanding Application Security Groups topic.

Get Service Instance GUID

Run cf service INSTANCE_NAME --guid to get the guid of the service instance.

$ cf service my-mysql --guid
ca16f111-5073-40b7-973a-156c75dd3028

Check Available Security Groups

To see all available security groups, run cf security-groups.

$cf security-groups
Getting security groups as demo@anynines.com
OK

     Name                                         Organization     Space
#0   public_networks
#1   dns
#2   tcp_open
#3   guard_432fb752-876d-443b-a311-a075f4df2237   demonstrations   demo
#4   guard_ca16f111-5073-40b7-973a-156c75dd3028   demonstrations   demo

There we can see a security group with the named guard_ca16f111-5073-40b7-973a-156c75dd3028 was successfully created.

Note: In some circumstances, the connection between the application and the service instance is not possible. In this case, check to see if a security group was created.

Backup and Restore Service Instances

a9s MySQL provides an easy way to create backups and restore if needed.

Get Dashboard Address, Log In and Authorize

  1. Grap the dashboard URL with cf service SERVICE-NAME. “`bash $cf service my-mysql

Service instance: my-mysql Service: a9s-mysql Bound apps: Tags: Plan: mysql-single-small Description: This is a service creating and managing dedicated MySQL service instances and clusters, powered by the anynines Service Framework Documentation url: Dashboard: https://a9s-mysql-dashboard.aws.ie.a9s.eu/service-instances/ca16f111-5073-40b7-973a-156c75dd3028

Last Operation Status: update succeeded Message: Started: 2017-10-26T08:28:38Z Updated: 2017-10-26T08:28:38Z ”`

  1. Browse to the dashboard URL and authenticate on the redirected page with your Cloud Foundry credentials:

  2. Click Authorize to approve the authorization request:

Perform a Backup

On the dashboard, you can trigger a backup by clicking Trigger backup

service-dashboard

After a short period of time the backup will be queued and the backup process will soon start.

service-dashboard

Note: Depending on the size of the data, the backup will take some time.

Restore a Backup

  1. Open the dashboard again and select the backup you would like to restore.
  2. Click Restore and wait for the restore to trigger.

service-dashboard

Note: Depending on the size of the data, the restore will take some time.

service-dashboard

Make a Service Instance Locally Available

It is possible to access any of the a9s Data Services locally. You can connect with a local client to the service for any purpose, such as debugging. CF provides a smart way to create SSH forward tunnels through a pushed application. For more information about this feature, see the Accessing Apps with SSH section of the CF documentation.

First, you must have an application bound to the service. To do this, see Bind an Application to a Service Instance.

Note: `cf ssh` support must be enabled in the platform. Your administrator can tell you whether it is enabled.

Get the Service URL and Credentials

You must first follow the procedure in Obtain Service Instance Access Credentials to get the hostname of the service and the user credentials.

$ cf env a9s-mysql-app
Getting env variables for app a9s-mysql-app in org test / space test as admin...
OK

System-Provided:
{
  "VCAP_SERVICES": {
   "a9s-mysql": [
    {
      "credentials": {
       "dns_servers": [
        "10.0.4.13",
        "10.0.5.5",
        "10.0.6.5"
       ],
       "host": "d566e59.service.dc1.a9s-mysql-consul",
       "host_ip": "10.0.10.4",
       "host_ips": [
        "10.0.8.4",
        "10.0.9.4",
        "10.0.10.4"
       ],
       "hosts": [
        "d566e59-mysql-0.node.dc1.a9s-mysql-consul",
        "d566e59-mysql-1.node.dc1.a9s-mysql-consul",
        "d566e59-mysql-2.node.dc1.a9s-mysql-consul"
       ],
       "name": "d566e59",
       "password": "a9s-password",
       "port": 3306,
       "uri": "mysql://a9s-brk-usr:a9s-password@d566e59.service.dc1.a9s-mysql-consul:3306/d566e59",
       "username": "a9s-brk-usr"
      },
      "instance_name": "mymysql",
      "label": "a9s-mysql101",
      "name": "mymysql",
      "plan": "mysql-cluster-small",
      "provider": null,
      "syslog_drain_url": null,
      "tags": [
       "sql",
       "database",
       "object-relational",
       "consistent"
     ]
    }
   ]
  }
}
...

Note the host d566e59.service.dc1.a9svs, the username a9s-brk-usr, and the password a9s-password. You will need these in the next step.

Create a Tunnel to The Service

With cf ssh, you can create am SSH forward tunnel to the management dashboard. Use port 3306 to connect to the a9s MySql Instance.

$ cf ssh a9s-mysql-app -L 3306:d67901c.service.dc1.a9svs:3306
vcap@956aaf4e-6da9-4f69-4b1d-8e631a403312:~$

When the SSH tunnel is open, you can access the instance using the address localhost:3306.

Note: Be sure to close the session by running exit.

Service keys

To gain access to the service manually rather than binding apps to it you can use service keys.

Creating a Service Key

To create a key to the service instance mysql1 call nykey run:

cf create-service-key mysql1 mykey

Listing Service Keys

To list all the keys for the mysql1 service instance run this:

cf service-keys mysql1

Accessing Service Keys

To obtain the key mykey from the mysql1 service instance run:

cf service-key mysql1 mykey

Deleting Service Keys

To delete a service key mykey from the service instance mysql1 run:

cf delete-service-key mysql1 mykey
Create a pull request or raise an issue on the source for this page in GitHub