Knative Functions¶
Write and run a small Go HTTP function locally, then optionally deploy it as a Knative Service. You can start here without a Kubernetes cluster or completing Quickstart. It is also a follow-on for readers who have finished Quickstart; it is not a prerequisite for its Serving and Eventing lessons.
Knative Functions provides a simple programming model for using functions on Knative, without requiring in-depth knowledge of Knative, Kubernetes, containers, or dockerfiles.
Knative Functions enables you to easily create, build, and deploy stateless, event-driven functions as Knative Services by using the func CLI.
For containerized workflows, func builds an Open Container Initiative (OCI) format image for you. Local builds and runs do not publish that image to a registry by default. Deployment normally builds the image when necessary, publishes it to your configured registry, and creates or updates a Knative Service.
You can create functions and manage function workflows by using the func CLI, or by using the kn func plugin for the Knative CLI.
Your local learning route¶
Use standalone func and the pack builder throughout this exercise. Have a running Docker-compatible daemon, a text editor, and network access to download the CLI, builder images, and Go dependencies. No registry account, running image registry, or Kubernetes credentials are needed for the local steps. The example image prefix is only a local name; nothing is published.
The handler example uses the Go HTTP template from Functions' knative-v1.24.0 release; its CLI version is 0.51.0. The installation lesson selects that release so the generated code matches the edit below. The template and taught command options have been checked against this release's source; historical v1.23 tests do not establish that this v1.24 walkthrough has run end to end.
- Install func.
- Create the project and edit its Go handler.
- Run and invoke it locally. Confirm the response body says
Hello from Knative Functions!. This completes the local exercise. - Optionally, publish and deploy after arranging a writable registry and a Knative Serving cluster. If you need a disposable cluster at that point, follow Quickstart installation.
For alternative workflows after this exercise, use the Functions task guides. You do not need to choose another builder here.
Previous: Tutorial catalog · Next: Install func