Bind backing services to your application

You can bind backing services to your application. The procedures in this topic use the Where for Dinner? sample application to demonstrate how to bind services to an app in a Space.

The procedures in Deploy your first application using Spaces bind backing services to the Where for Dinner? app. The procedures in this topic deploy the Where for Dinner? app without backing services and describe how to bind services to the app.

You use the tanzu services CLI plug-in to create and bind Bitnami services or pre-provisioned services, based on your requirements.

  • Bitnami services provide a quick and easy way to add backing services in Spaces. However, the Bitnami services are limited to single availability targets and replica sets. Bitnami services are more suitable for development environments, to allow easy self-service and quick iteration.

  • Pre-provisioned services require additional configuration. They can be used to make services from the provider of your choice available across multiple availability targets. Pre-provisioned services are more suitable for staging and production environments, to provide higher availability and resiliency.

For more information about binding services, see What are Services and Service Bindings.

Before you begin

Make sure that you have performed the following tasks:

  • Followed the steps in Create an application environment using Spaces to create a Space to deploy the Where for Dinner? application.

  • Configured Tanzu CLI:

    • Installed the Tanzu CLI v1.3.0 or higher. Tanzu CLI is required for CLI procedures. See Install the Tanzu CLI.

    • Installed the Tanzu CLI app-developer plugin group:

      tanzu plugin install --group vmware-tanzu/app-developer
      

If you want to create a PreProvisionedService in a Space, decide on the following:

Overview of the steps

Deploying the Where for Dinner? example application to a Space and binding services to the application involves the following broad steps:

  1. Clone the application Git repository.
  2. Update the routing configuration.
  3. Deploy the Where for Dinner? example application in your Space.
  4. Create backing services using Bitnami Services.
  5. Create backing services using Pre-Provisioned Services.
  6. Access the Application.

Clone the application Git repository

The sample Application Accelerator Git repository contains the required Carvel packages and YAML configuration files for the Where for Dinner? example application.

  1. Clone the repository.

    git clone https://github.com/vmware-tanzu/application-accelerator-samples
    
  2. Go to the directory that contains accelerator samples.

    cd application-accelerator-samples
    
  3. Check out the wfd-spaces-ga branch.

    git checkout wfd-spaces-ga
    
  4. Go to the directory that contains the application resources.

    cd where-for-dinner-services-cli
    

Update the routing configuration

The routing configuration for the Where for Dinner? app is set to use the where-for-dinner hostname.

Note

This procedure is optional.

Where For Dinner? uses an HTTPRoute resource to create an externally resolvable and accessible endpoint on the Internet.

  1. Open .tanzu/config/k8sGatewayRoutes.yaml in a text editor.
  2. Update .tanzu/config/k8sGatewayRoutes.yaml to use the hostname at which you want your app to be available.

    You set the host name portion of the externally addressable address in the spec.parentRefs.sectionName field of the HTTPRoute resource. Set the sectionName value to the desired hostname with the prefix http-. For example, to obtain the hostname where-for-dinner, set http-where-for-dinner.

  3. Save .tanzu/config/k8sGatewayRoutes.yaml.

For more information about how to configure HTTP routing, see Add HTTP Routing to an Application

Deploy the Where for Dinner? example application in your Space

The Where for Dinner? example application consists of the following resources:

  • Package and PackageInstall
  • Secret resources for configuring the PackageInstall resources
  • Routing resources for Spring Cloud Gateway and Kubernetes Gateway APIs

Because most of the configuration is done for you, only need to deploy the application.

  1. Set the Tanzu CLI to the Tanzu Platform context you created in Set the Tanzu CLI context to an organization.

    tanzu login
    
  2. Set the project to use.

    1. View the available list of projects.

      tanzu project list
      
    2. Set the project.

      tanzu project use PROJECT-NAME
      
  3. Set the Space to use for your deployment.

    tanzu space use `SPACE-NAME`
    
  4. Build and deploy the Where for Dinner? application.

    tanzu deploy
    

Create backing services using Bitnami Services

The Where for Dinner? application is a stateful application, which means that it requires backing services to store state. Where for Dinner? uses MySQL and Redis to store state. This section describes how to create low-cost development Bitnami Services.

The Bitnami backing services use services from the Bitnami Catalog deployed to the Space. Backing services from Bitnami are deployed in each Availability Target and replica. Therefore, if you have multiple Availability Targets or replicas, you have multiple instances of the Bitnami services deployed. Service instances do not replicate to each other, so deployed applications are functional but data is not replicated between replicas and Availability Targets.

Note

To provide backing services that support multiple Availability Targets or replicas, you can use a pre-provisioned cloud-based service that supports this use case. For information about using the Where for Dinner? application with Amazon Web Services, see Deploy your first application using Spaces.

To create Bitnami backing services:

  1. View the services that are available in the Space.

    tanzu services list
    

    There are probably no services available in the Space.

  2. List the available Service types.

    tanzu services type list
    

    You will see the available services.

    NAME
    RabbitmqCluster
    KafkaInstance
    RedisCluster
    MongoDBInstance
    PostgreSQLInstance
    MySQLInstance
    
  3. Create Bitnami MySql and RabbitMQ services.

    tanzu services create MySQLInstance/where-for-dinner-mysql
    
    tanzu services create RabbitmqCluster/where-for-dinner-rabbitmq
    
  4. Verify that the services are now available in the Space.

    tanzu services list
    
  5. Run tanzu services bind to bind services to workloads.

    If a tanzu.yml configuration file exists in the project with configuration.dev.paths configured, tanzu services bind prompts you to create service bindings with the same names as the container app service bindings that exist on disk. If tanzu.yml does not exist or if configuration.dev.paths is not configured, you are given the option to create new service bindings and are prompted to add these new bindings to the container app on the disk.

    tanzu services bind MySQLInstance/where-for-dinner-mysql ContainerApp/where-for-dinner-availability
    tanzu services bind MySQLInstance/where-for-dinner-mysql ContainerApp/where-for-dinner-search
    tanzu services bind RabbitmqCluster/where-for-dinner-rabbitmq ContainerApp/where-for-dinner-availability
    tanzu services bind RabbitmqCluster/where-for-dinner-rabbitmq ContainerApp/where-for-dinner-search
    tanzu services bind RabbitmqCluster/where-for-dinner-rabbitmq ContainerApp/where-for-dinner-search-proc
    tanzu services bind RabbitmqCluster/where-for-dinner-rabbitmq ContainerApp/where-for-dinner-notify
    
  6. Display information about the MySQL and RabbitMQ services and their bindings by running tanzu services get.

    tanzu services get MySQLInstance/where-for-dinner-mysql
    
    tanzu services get RabbitmqCluster/where-for-dinner-rabbitmq
    
  7. (Optional) Use kubectl to get detailed information about the status of the underlying MySQL and RabbitMQ services.

    kubectl get syncresourcesets -l kind=MySQLInstance -l resource-name=where-for-dinner-mysql -o yaml
    kubectl get syncresourcesets -l kind=RabbitmqCluster -l resource-name=where-for-dinner-rabbitmq -o yaml
    

The workloads might temporarily fail while the Bitnami Services are deployed. The workloads successfully start after the MySQL and RabbitMQ services are available.

If you do not intend to use Pre-provisioned services, proceed to Viewing the application and Service instances.

Create backing services using pre-provisioned services

You can also attach existing services to apps. This will often be the case when consuming production-level services such as cloud-based services. To add a pre-provisioned service to the service directory, you create a PreProvisionedService resource.

  1. In a Space, run tanzu services create to create a PreProvisionedService.

    tanzu services create PreProvisionedService/prod-mysql
    

    This command configures a PreProvisionedService resource with a binding connector of the selected type. See Spring Cloud Bindings for the applicable types.

  2. List the services that are available in the Space and that verify the PreProvisionedService was added.

    tanzu services list
    

View the application and service instances in Tanzu Platform hub

To access the Where for Dinner? example application in a browser:

  1. On the Tanzu Platform hub, click Application Spaces > Spaces.
  2. Click the name of the Space to which you deployed the Where for Dinner? application.
  3. Click the Space URL.
  4. The Space URL is currently written for HTTPS connections. Change the URL to HTTP.

The topology graph for the application uses the service mesh components to generate the topology. This requires traffic to be generated within the application for the full application topology to appear.

You can explore the Service Instances available in your Space by navigating to the Service Instance tab within the Space. From here you can access individual service instances and see more information about the bindings and connections to your applications.

Delete services

When the services are no longer required, you can unbind them from the app and delete them.

  1. To unbind and delete the Services, run the following commands:

    tanzu services unbind MySQLInstance/where-for-dinner-mysql Deployment/availability --alias db
    
    tanzu services unbind MySQLInstance/where-for-dinner-mysql Deployment/where-for-dinner-search --alias db
    
    tanzu services unbind RabbitmqCluster/where-for-dinner-rabbitmq Deployment/availability --alias rmq
    
    tanzu services unbind RabbitmqCluster/where-for-dinner-rabbitmq Deployment/where-for-dinner-search --alias rmq
    
    tanzu services unbind RabbitmqCluster/where-for-dinner-rabbitmq Deployment/search-proc --alias rmq
    
    tanzu services unbind RabbitmqCluster/where-for-dinner-rabbitmq Deployment/where-for-dinner-notify --alias rmq
    
    tanzu services delete MySQLInstance/where-for-dinner-mysql
    
    tanzu services delete RabbitmqCluster/where-for-dinner-rabbitmq
    
  2. (Optional) Verify the services were deleted.

    tanzu services list
    
check-circle-line exclamation-circle-line close-line
Scroll to top icon