Function accelerators make it easy to create and build HTTP or event-driven applications that are portable across cloud providers and on-premises Kubernetes environments. Function workloads can quickly scale horizontally based on burst traffic, and minimize the application code needed to perform common tasks.
How to create and deploy an HTTP or CloudEvent function from an Application Accelerator starter template in an online or air-gapped environment.
Note- Beta Support for function workloads in Java and Python.
The function experience on Tanzu Application Platform enables you to deploy functions, use starter templates to bootstrap your function, and write only the code that matters to your business. You can run a single CLI command to deploy your 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 function buildpack manages the webserver. This means that you can focus on your business logic.
- 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.
Supported languages and frameworks
For HTTP and CloudEvents:
Language/framework | HTTP | CloudEvents |
---|---|---|
Java | ✓ | ✓ |
Python | ✓ | ✓ |
NodeJS | ✓ | N/A |
For REST API:
Language/framework | GET | POST |
---|---|---|
Java | N/A | ✓ |
Python | ✓ | ✓ |
NodeJS | ✓ | ✓ |
Prerequisites
Before using function workloads on Tanzu Application Platform, complete the following prerequisites:
- Follow all instructions to install Tanzu Application Platform:
- Follow all instructions in Set up developer namespaces to use installed packages.
Create a function project from an accelerator
To create a function project from an accelerator:
- From the Tanzu Application Platform GUI portal, click Create on the left navigation bar to see the list of available accelerators.
- Locate the function accelerator in the language or framework of your choice and click CHOOSE.
- Provide a name for your function project and your function.
- If you are creating a Java function, select a project type.
- Provide a Git repository to store the files for the accelerator.
- Click NEXT STEP, verify the provided information, and then 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.
Create a function project using the Tanzu CLI
From the CLI, to generate a function project using an accelerator template and then download the project artifacts as a ZIP file:
- Verify 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
whereDOMAIN
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
Usehttp://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
Usehttp://localhost:8877
as the URL.
- For installations configured with a shared ingress, use
- 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 arehttp
orcloudevents
. CloudEvents is experimental.APPLICATION-ACCELERATOR-URL
is the URL for the Application Accelerator server that you retrieved in the previous step.
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 your function
To deploy and verify your function:
- Deploy the function accelerator by running the
tanzu apps workload
create command:tanzu apps workload create functions-accelerator-python \ --local-path . \ --source-image SOURCE-IMAGE \ --type web \ --yes --namespace YOUR-DEVELOPER-NAMESPACE
Where:SOURCE-IMAGE
is a writable repository in your registry in the formREGISTRY/IMAGE:TAG
.- 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”.
YOUR-DEVELOPER-NAMESPACE
is the namespace you configured earlier.
- View the build and runtime logs for your application by running the
tail
command:tanzu apps workload tail functions-accelerator-python --since 10m --timestamp --namespace YOUR-DEVELOPER-NAMESPACE
WhereYOUR-DEVELOPER-NAMESPACE
is the namespace configured earlier. - 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 --namespace YOUR-DEVELOPER-NAMESPACE
WhereYOUR-DEVELOPER-NAMESPACE
is the namespace configured earlier. - (Optional) You can test your function using a curl command. Java function POST example:
curl -w'\n' URL-FROM-YOUR-WORKLOAD-KNATIVE-SERVICES-SECTION \ -H "Content-Type: application/json" \ -d '{"firstName":"John", "lastName":"Doe"}'
For more details Tanzu Application Platform