This topic describes how to enable Tanzu Application Services (TAS) applications to connect and utilize Tanzu Postgres database services.

Prerequisites

  • Tanzu Postgres has been successfully installed on a Kubernetes cluster.
  • The external public ingress service type of the instance is set to LoadBalancer. See Deploying a Postgres Instance.
  • You have deployed an application to TAS, and the application is able to reach the Kubernetes cluster ingress points.

Binding an Application

  1. Export the environment variables $dbname, $username, $password, $host, and $port, described in Accessing Postgres with External Clients.

  2. (Optional) From your computer validate that the Postgres instance is reachable from the location where TAS is deployed, by using a command similar to:

    # create a CF SSH tunnel, this will hang and you need to leave it open until you're done with this step
    $ cf ssh <appname> -L 54320:$host:$port
    

    which returns similar to:

    vcap@f00949bd-6601-4731-6f7e-e859:~$
    

    where f00949bd-6601-4731-6f7e-e859 is an example GUID. In a new window or tab, use psql to test the connection:

    $ PGPASSWORD=$password psql -h 127.0.0.1 -p 54320 -U $username -d $dbname
    
    psql (11.13 (VMware Postgres 11.13.1))
    Type "help" for help.
    
    postgres-sample=#
    
  3. Choose a name and create the user provided service:

    $ cf create-user-provided-service my-postgres-instance -p "{\"uri\":\"postgres://$username:$password@$host:$port/$dbname?sslmode=require\"}"
    

    For more details, see User-Provided Service Instances.

  4. Bind, restage, and use the service as you would normally with a "cf marketplace" provisioned SQL instance. See Bind a Service Instance to an App for an example of this process, and Restage Your App.

    Like any data service, the application will automatically connect to the database instance depending on the buildpack. If autoconnect is not supported, the application will have to manually make use of the uri service credential to make a connection.

    Bound service credentials are available at runtime to TAS applications via the DATABASE_URL and VCAP_SERVICES environment variables. For further details see DATABASE_URL in TAS for VMs Environment Variables documentation.

check-circle-line exclamation-circle-line close-line
Scroll to top icon