You can bind backing services to your Kubernetes application in Tanzu Platform. The procedures in this topic use the Where for Dinner? example 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.5.1 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:
-
Number of binding connectors: Deciding whether to use a single or many binding connectors and how to name them. See Specifying Multiple Binding Connectors.
-
Connectivity details: The connectivity details of each Availability Target in the context of each Binding Connector. See Binding Details and Availability Targets.
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:
- Clone the application Git repository.
- Update the routing configuration.
- Deploy the Where for Dinner? example application in your Space.
- Create backing services using Bitnami Services.
- Create backing services using Pre-Provisioned Services.
- 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.
-
Clone the repository.
git clone https://github.com/vmware-tanzu/application-accelerator-samples
-
Go to the directory that contains accelerator samples.
cd application-accelerator-samples
-
Check out the
wfd-spaces-ga
branch.git checkout wfd-spaces-ga
-
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.
This procedure is optional.
Where For Dinner? uses an HTTPRoute
resource to create an externally resolvable and accessible endpoint on the Internet.
- Open
.tanzu/config/k8sGatewayRoutes.yaml
in a text editor. -
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 theHTTPRoute
resource. Set thesectionName
value to the desired hostname with the prefixhttp-
. For example, to obtain the hostnamewhere-for-dinner
, sethttp-where-for-dinner
. -
Save
.tanzu/config/k8sGatewayRoutes.yaml
.
For more information about how to configure HTTP routing, see Enable HTTP traffic to reach your app.
Deploy the Where for Dinner? example application in your Space
The Where for Dinner? example application consists of the following resources:
Package
andPackageInstall
- 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.
-
Set the Tanzu CLI to the Tanzu Platform context you created in Set the Tanzu CLI context to an organization.
tanzu login
-
Set the project to use.
-
View the available list of projects.
tanzu project list
-
Set the project.
tanzu project use PROJECT-NAME
-
-
Set the Space to use for your deployment.
tanzu space use `SPACE-NAME`
-
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.
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:
-
View the services that are available in the Space.
tanzu services list
There are probably no services available in the Space.
-
List the available Service types.
tanzu services type list
You will see the available services.
NAME RabbitmqCluster KafkaInstance RedisCluster ValkeyCluster MongoDBInstance PostgreSQLInstance MySQLInstance CassandraCluster Neo4jInstance
-
Create Bitnami MySQL and RabbitMQ services by running these commands:
tanzu services create MySQLInstance/where-for-dinner-mysql --skip-bind-prompt
tanzu services create RabbitmqCluster/where-for-dinner-rabbitmq --skip-bind-prompt
If you run the command without the
--skip-bind-prompt
flag, you trigger thetanzu service bind
flow and you will be prompted to select an application to bind to.The
tanzu services create
command is interactive, allowing you to configure parameters specific to each service type. For example:Configure parameters for the RabbitmqCluster/where-for-dinner-rabbitmq. ? Parameter [Use arrows to move, type to filter] > <finish configuration> replicas (1) storageGB (1)
The CLI presents optional parameters with their default values in brackets. After you provide values for all required parameters and only optional parameters remain, select
<finish configuration>
to complete creating the service. -
Verify that the services are now available in the Space by running:
tanzu services list
You can skip this step and directly run
tanzu services create
to enter the interactive flow. You must select> Provision New Service
first to see all of the service types. -
Run
tanzu services bind
to bind services to workloads.If there is a
tanzu.yml
configuration file in the project withconfiguration.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 ifconfiguration.dev.paths
is not configured, you can create new service bindings and are prompted to add these new bindings to the container app on 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
-
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
-
(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.
-
In a Space, run
tanzu services create
to create aPreProvisionedService
.tanzu services create PreProvisionedService/prod-mysql --skip-bind-prompt
This command configures a
PreProvisionedService
resource with a binding connector of the selected type. See Spring Cloud Bindings for the applicable types. -
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 the Tanzu Platform UI
To access the Where for Dinner? example application in a browser:
- In the Tanzu Platform UI, click Application Spaces > Spaces.
- Click the name of the Space to which you deployed the Where for Dinner? application.
- Click the Space URL.
- 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.
-
To unbind and delete the Services, run the following commands. Alternatively, run
tanzu service unbind
directly and use the multi-select prompt to unbind multiple services with a single command.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
-
(Optional) Verify the services were deleted.
tanzu services list
Content feedback and comments