Consume services on Tanzu Application Platform

This how-to guide walks the application developer through deploying two application workloads and configuring them to communicate over RabbitMQ. You will learn about the tanzu services CLI plug-in and the most important APIs for working with services on Tanzu Application Platform.

Important: This walkthrough assumes that the service operator and application operator has already:

  • Set up a service.
  • Created a service instance.
  • Claimed the service instance.

This is described in Set up services for consumption by developers.

What you will do

  • Inspect the resource claim created for the service instance by the application operator.
  • Bind the application workload to the ResourceClaim so the workload utilizes the service instance.

Before you begin, for important background, see About consuming services on Tanzu Application Platform.

Overview

The following diagram depicts a summary of what this walkthrough covers, including the work of the service and application operators described in Set up services for consumption by developers.

Diagram shows the default namespace and service instances namespace. The default namespace has two application workloads, each connected to a service binding. The service bindings connect to the service instance in the service instances namespace through a resource claim.

Bear the following observations in mind as you work through this guide:

  1. There is a clear separation of concerns across the various user roles.

    • The life cycle of workloads is determined by application developers.
    • The life cycle of resource claims is determined by application operators.
    • The life cycle of service instances is determined by service operators.
    • The life cycle of service bindings is implicitly tied to the life cycle of workloads.
  2. ProvisionedService is the contract allowing credentials and connectivity information to flow from the service instance, to the resource claim, to the service binding, and ultimately to the application workload. For more information, see ProvisionedService on GitHub.

Prerequisites

Before following this walkthrough, you must:

  1. Have access to a cluster with Tanzu Application Platform installed.
  2. Have downloaded and installed the Tanzu CLI and the corresponding plug-ins.
  3. Have set up the default namespace to use installed packages and use it as your developer namespace. For more information, see Set up developer namespaces to use installed packages.
  4. Ensure your Tanzu Application Platform cluster can pull source code from GitHub.
  5. Ensure the service operator and application operator has completed the work of setting up the service, creating the service instance, and claiming the service instance, as described in Set up services for consumption by developers.

As application developer, you are now ready to inspect the resource claim created for the service instance by the application operator in Set up services for consumption by developers and use it to bind to application workloads.

Bind an application workload to the service instance

This section covers:

  • Using tanzu service claim list and tanzu service claim get to find information about the claim to use for binding.
  • Using tanzu apps workload create with the --service-ref flag to create a workload and bind it to the service instance.

You must create application workloads and bind them to the service instance using the claim.

In Tanzu Application Platform, service bindings are created when you create application workloads that specify .spec.serviceClaims. In this section, you create such workloads by using the --service-ref flag of the tanzu apps workload create command.

To create an application workload:

  1. Inspect the claims in the developer namespace to find the value to pass to --service-ref command by running:

    tanzu service claim list
    

    Expected output:

      NAME   READY  REASON
      rmq-1  True
    
  2. Retrieve detailed information about the claim by running:

    tanzu service claim get rmq-1
    

    Expected output:

    Name: rmq-1
    Status:
      Ready: True
    Namespace: default
    Claim Reference: services.apps.tanzu.vmware.com/v1alpha1:ResourceClaim:rmq-1
    Resource to Claim:
      Name: rmq-1
      Namespace: service-instances
      Group: rabbitmq.com
      Version: v1beta1
      Kind: RabbitmqCluster
    
  3. Record the value of Claim Reference from the previous command. This is the value to pass to --service-ref to create the application workload.

  4. Create the application workload by running:

    tanzu apps workload create spring-sensors-consumer-web \
      --git-repo https://github.com/sample-accelerators/spring-sensors-rabbit \
      --git-branch main \
      --type web \
      --label app.kubernetes.io/part-of=spring-sensors \
      --annotation autoscaling.knative.dev/minScale=1 \
      --service-ref="rmq=services.apps.tanzu.vmware.com/v1alpha1:ResourceClaim:rmq-1"
    
    tanzu apps workload create \
      spring-sensors-producer \
      --git-repo https://github.com/tanzu-end-to-end/spring-sensors-sensor \
      --git-branch main \
      --type web \
      --label app.kubernetes.io/part-of=spring-sensors \
      --annotation autoscaling.knative.dev/minScale=1 \
      --service-ref="rmq=services.apps.tanzu.vmware.com/v1alpha1:ResourceClaim:rmq-1"
    

    Using the --service-ref flag instructs Tanzu Application Platform to bind the application workload to the service provided in the ref.

    Note: You are not passing a service ref to the RabbitmqCluster service instance directly, but rather to the resource claim that has claimed the RabbitmqCluster service instance. See the consuming services diagram at the beginning of this walkthrough.

  5. After the workloads are ready, visit the URL of the spring-sensors-consumer-web app. Confirm that sensor data, passing from the spring-sensors-producer workload to the create spring-sensors-consumer-web workload using the RabbitmqCluster service instance, is displayed.

Further use cases and reading

There are more service use cases not covered in this getting started guide. See the following:

Use Case Short Description
Consuming AWS RDS on Tanzu Application Platform Using the Controllers for Kubernetes (ACK) to provision an RDS instance and consume it from a Tanzu Application Platform workload.
Involves making a third-party API consumable from Tanzu Application Platform.
Consuming AWS RDS on Tanzu Application Platform with Crossplane Using Crossplane to provision an RDS instance and consume it from a Tanzu Application Platform workload.
Involves making a third-party API consumable from Tanzu Application Platform.
Consuming Google Cloud SQL on Tanzu Application Platform with Config Connector Using GCP Config Connector to provision a Cloud SQL instance and consume it from a Tanzu Application Platform workload.
Involves making a third-party API consumable from Tanzu Application Platform.
Consuming Google Cloud SQL on Tanzu Application Platform with Crossplane Using Crossplane to provision a Cloud SQL instance and consume it from a Tanzu Application Platform workload.
Involves making a third-party API consumable from Tanzu Application Platform.
Direct Secret References Binding to services running external to the cluster, for example, an in-house oracle database.
Binding to services that do not conform with the binding specification.
Dedicated Service Clusters (Experimental) Separates application workloads from service instances across dedicated clusters.

For more information about the APIs and concepts underpinning Services on Tanzu Application Platform, see the Services Toolkit Component documentation.

Next steps

Now that you’ve completed the Getting started guides, learn about:

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