This topic describes how to create and deploy an HTTP function from an application accelerator starter template.
The function experience on Tanzu Application Platform enables developers to deploy functions, use starter templates to bootstrap their function and write only the code that matters to your business. Developers can run a single CLI command to deploy their functions to an auto-scaled cluster.
Functions provide a quick way to get started writing an application. Compared with a traditional application:
Functions have a single entry-point and perform a single task. This means that functions can be easier to understand and monitor.
The initial webserver and application boilerplate are managed by the function supply chain. This means that you can update the webserver and application boilerplate without needing to update each function application.
A traditional webserver application might be a better fit if you want to implement an entire website or API in a single container
Important: Beta features have been tested for functionality, but not performance. Features enter the beta stage so that customers can gain early access, and give feedback on the design and behavior. Beta features might undergo changes based on this feedback before the end of the beta stage. VMware discourages running beta features in production. VMware cannot guarantee that you can upgrade any beta feature in the future.
Before using function workloads on Tanzu Application Platform, complete the following prerequisites:
Follow all instructions in Installing Tanzu Application Platform.
Download and install the kp CLI for your operating system from the Tanzu Build Service page on Tanzu Network. For more information, see the kp CLI help text on GitHub.
Follow all instructions in Set up developer namespaces to use installed packages.
To use the function buildpacks
, you must upload their buildpackages to Build Service stores.
Add the function’s buildpackages to the default ClusterStore by running:
kp clusterstore add default \
-b registry.tanzu.vmware.com/python-function-buildpack-for-vmware-tanzu/python-buildpack-with-deps:0.0.11 \
-b registry.tanzu.vmware.com/java-function-buildpack-for-vmware-tanzu/java-buildpack-with-deps:0.0.6
Create and save a new ClusterBuilder. Run one of the following commands depending on the descriptor you used in the buildservice
section of your tap-values.yaml
file:
For the full descriptor, run:
kp clusterbuilder save function --store default -o - <<EOF
---
- group:
- id: tanzu-buildpacks/python
- id: kn-fn/python-function
- group:
- id: tanzu-buildpacks/java-native-image
- id: kn-fn/java-function
- group:
- id: tanzu-buildpacks/java
- id: kn-fn/java-function
EOF
If you still want to use default Java and Python buildpacks for non-functions workloads, add optional: true
flags for cluster builder groups. This does not enable the full capability of non-function workloads provided by the default ClusterBuilder. For example:
kp clusterbuilder save function --store default -o - <<EOF
---
- group:
- id: tanzu-buildpacks/python
- id: kn-fn/python-function
optional: true
- group:
- id: tanzu-buildpacks/java-native-image
- id: kn-fn/java-function
optional: true
- group:
- id: tanzu-buildpacks/java
- id: kn-fn/java-function
optional: true
EOF
For the lite descriptor, run:
kp clusterbuilder save function --store default -o - <<EOF
---
- group:
- id: tanzu-buildpacks/python-lite
- id: kn-fn/python-function
- group:
- id: tanzu-buildpacks/java-native-image-lite
- id: kn-fn/java-function
- group:
- id: tanzu-buildpacks/java-lite
- id: kn-fn/java-function
EOF
If you still want to use default Java and Python buildpacks for non-functions workloads, add optional: true
flags for cluster builder groups. This does not enable the full capability of non-function workloads provided by the default ClusterBuilder. For example:
kp clusterbuilder save function --store default -o - <<EOF
---
- group:
- id: tanzu-buildpacks/python-lite
- id: kn-fn/python-function
optional: true
- group:
- id: tanzu-buildpacks/java-native-image-lite
- id: kn-fn/java-function
optional: true
- group:
- id: tanzu-buildpacks/java-lite
- id: kn-fn/java-function
optional: true
EOF
After creating the ClusterBuilder, update your tap-values.yaml
configuration to use the cluster builder you created. See the following example:
ootb_supply_chain_basic:
cluster_builder: function
registry:
server: "SERVER"
repository: "REPO"
Where:
SERVER
is your server. For example, index.docker.io
.REPO
is your repository.Apply the update by going to the directory containing tap-values.yaml
and running:
tanzu package installed update tap -p tap.tanzu.vmware.com -v VERSION --values-file tap-values.yaml -n tap-install
Where VERSION
is the version of Tanzu Application Platform GUI you have installed. For example, 1.0.2
.
Application Accelerator is a component of Tanzu Application Platform. An accelerator contains your enterprise-conformant code and configurations that developers can use to create new projects that automatically follow the standards defined in your accelerators.
The accelerator ZIP file contains a file called k8s-resource.yaml. This file contains the resource manifest for the function accelerator.
Download the ZIP file for the appropriate accelerator:
Expand the accelerator ZIP file in your target cluster with Tanzu Application Platform GUI installed.
To update the Application Accelerator templates in Tanzu Application Platform GUI, you must apply the k8s-resource.yaml. Run the following command in your terminal in the folder where you expanded the ZIP file:
kubectl apply -f k8s-resource.yaml --namespace accelerator-system
Refresh Tanzu Application Platform GUI to reveal function accelerator(s).
It might take time for Tanzu Application Platform GUI to refresh the catalog to see your added function accelerators.
From the Tanzu Application Platform GUI portal, click Create on the left navigation bar to see the list of available accelerators.
Locate the Function Buildpacks accelerator and click CHOOSE.
Provide a name for your function project and function. If creating a Java function, select a project type*. Select HTTP for your event type. Provide a Git repository to store this accelerator’s files. Click NEXT STEP, verify the provided information, and click CREATE.
After the Task Activity processes complete, click DOWNLOAD ZIP FILE.
After downloading the ZIP file, expand it in a workspace directory and follow your preferred procedure for uploading the generated project files to a Git repository for your new project.
From the CLI, you can generate a function project using an accelerator template, then download the project artifacts as a ZIP file.
Validate that you have added the function accelerator template to the application accelerator server by running:
tanzu accelerator list
Get the server-url
for the Application Accelerator server. The URL depends on the configuration settings for Application Accelerator:
For installations configured with a shared ingress, use https://accelerator.DOMAIN
where DOMAIN
is provided in the values file for the accelerator configuration.
For installations using a LoadBalancer, look up the External IP address by running:
kubectl get -n accelerator-system service/acc-server
Use http://EXTERNAL-IP
as the URL.
For any other configuration, you can use port forwarding by running:
kubectl port-forward service/acc-server -n accelerator-system 8877:80
Use http://localhost:8877
as the URL.
Generate a function project from an accelerator template by running:
tanzu accelerator generate ACCELERATOR-NAME \
--options '{"projectName": "FUNCTION-NAME", "interfaceType": "TYPE"}' \
--server-url APPLICATION-ACCELERATOR-URL
Where:
ACCELERATOR-NAME
is the name of the function accelerator template you want to use.FUNCTION-NAME
is the name of your function project.TYPE
is the interface you want to use for your function. Available options are http
or cloudevents
. CloudEvents is experimental.APPLICATION-ACCELERATOR-URL
is the URL for the Application Accelerator server that you retrieved in the previous step.For example:
tanzu accelerator generate java-function \
--options '{"projectName": "my-func", "interfaceType": "http"}' \
--server-url http://localhost:8877
After generating the ZIP file, expand it in your directory and follow your preferred procedure for uploading the generated project files to a Git repository for your new project.
Deploy the function accelerator by running the tanzu apps workload
create command:
tanzu apps workload create functions-accelerator-python \
--local-path . \
--source-image REGISTRY/IMAGE:TAG \
--type web \
--yes
Where:
--source-image
is a writable repository in your registry.Harbor has the form: “my-harbor.io/my-project/functions-accelerator-python”.
Docker Hub has the form: “my-dockerhub-user/functions-accelerator-python”.
Google Cloud Registry has the form: “gcr.io/my-project/functions-accelerator-python”.
View the build and runtime logs for your application by running the tail command:
tanzu apps workload tail functions-accelerator-python --since 10m --timestamp
After the workload is built and running, you can view the web application in your browser. To view the URL of the web application, run the following command and then ctrl-click the Workload Knative Services URL at the bottom of the command output.
tanzu apps workload get functions-accelerator-python