diff --git a/config/redirects.yml b/config/redirects.yml index 1a15338fbf..095e362964 100644 --- a/config/redirects.yml +++ b/config/redirects.yml @@ -240,3 +240,7 @@ plugins: versioned/getting-started/clean-up.md: versioned/getting-started/next-steps.md#clean-up versioned/bookstore/disclaimer/README.md: versioned/bookstore/disclaimer/disclaimer.md versioned/bookstore/extra-challenge/README.md: versioned/bookstore/extra-challenge/extra-challenges.md + versioned/functions/install-func.md: versioned/functions/running-functions.md + versioned/functions/creating-functions.md: versioned/functions/running-functions.md + versioned/functions/invoking-functions.md: versioned/functions/running-functions.md + versioned/functions/kafka-functions.md: versioned/functions/subscribing-functions.md diff --git a/docs/versioned/.nav.yml b/docs/versioned/.nav.yml index c04631218b..3c98e91b6d 100644 --- a/docs/versioned/.nav.yml +++ b/docs/versioned/.nav.yml @@ -28,15 +28,11 @@ nav: ############################################################################### - Functions: - Overview: functions/README.md - - Install: functions/install-func.md - - Create: functions/creating-functions.md - - Build: functions/building-functions.md - - Run locally: functions/running-functions.md - - Deploy: functions/deploying-functions.md - - Invoke: functions/invoking-functions.md - - Subscribe to events: functions/subscribing-functions.md - - Kafka: functions/kafka-functions.md - - Language packs: functions/language-packs.md + - Develop locally: functions/running-functions.md + - Build an image: functions/building-functions.md + - Deploy a function: functions/deploying-functions.md + - Connect events: functions/subscribing-functions.md + - Templates and runtimes: functions/language-packs.md ############################################################################### # Serving ############################################################################### diff --git a/docs/versioned/client/README.md b/docs/versioned/client/README.md index c05df275ee..28700ce25f 100755 --- a/docs/versioned/client/README.md +++ b/docs/versioned/client/README.md @@ -37,7 +37,7 @@ The `func` CLI enables you to create, build, and deploy Knative Functions withou ### Additional resources -- See [Installing Knative Functions](../functions/install-func.md). +- See [Develop locally — Prepare](../functions/running-functions.md#prepare). - See the [`func` documentation]({{ funcdocs() }}){target=_blank} in Github. ## Connecting CLI tools to your cluster diff --git a/docs/versioned/functions/README.md b/docs/versioned/functions/README.md index 70f9fc91d6..7bdb8d08fa 100644 --- a/docs/versioned/functions/README.md +++ b/docs/versioned/functions/README.md @@ -3,26 +3,31 @@ audience: developer components: - functions function: explanation +hide_prev: true +hide_next: true --- -# Knative Functions overview +# Knative Functions --8<-- "about-functions.md" -## Function templates +## Start here ---8<-- "functions-templates-intro.md" +New to Knative Functions? Follow [Try Functions](../getting-started/about-knative-functions.md) +to create, edit, and test a Go function locally — no Kubernetes cluster or +registry account required. -## Language packs +## Choose a task -Functions can be written in any language supported by the available [language packs](https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md){target=_blank}. - +- **[Develop locally](running-functions.md):** install `func`, create a project, + run it locally, and send HTTP or CloudEvents test requests. +- **[Build an image](building-functions.md):** build a container image locally + without running or deploying it. +- **[Deploy a function](deploying-functions.md):** deploy from your machine or + build and deploy remotely on a cluster with Tekton. +- **[Connect events](subscribing-functions.md):** subscribe a function to a + Knative Broker with Triggers, or consume Apache Kafka topics via sidecar. +- **[Templates and runtimes](language-packs.md):** choose a language and + HTTP/CloudEvents template, or use custom language-pack repositories. -## Getting started with functions - -Follow [Get started with Functions](../getting-started/about-knative-functions.md) -to create, change, and test a Go function locally. This is the same Functions -track linked from Get Started. Cluster deployment is optional and links to the -shared learning-cluster setup. - -For an existing project, use the how-to guides in this section. +For the full CLI reference, see the [`func` documentation]({{ funcdocs() }}){target=_blank}. diff --git a/docs/versioned/functions/building-functions.md b/docs/versioned/functions/building-functions.md index 7bca01c18f..ad1269179e 100644 --- a/docs/versioned/functions/building-functions.md +++ b/docs/versioned/functions/building-functions.md @@ -3,136 +3,81 @@ audience: developer components: - functions function: how-to +hide_prev: true +hide_next: true --- -# Building functions +# Build an image -Build a container image from an existing function project. The local procedure -builds only: it does not run, publish, or deploy the function. The optional -on-cluster workflow below builds **and deploys**, so choose it only when you want -that result. +`func build` turns a function project into a container image. It does not push +anything to a registry by default (add `--push` to push the image), and it never +deploys. For standard deployments, skip this separate build step: +[`func deploy`](deploying-functions.md) builds, pushes, and deploys in one command. -## Local builds +## Requirements -### Prerequisites +- An initialized function project containing `func.yaml` and source code. + [Create a project](running-functions.md#create-a-project) if needed. +- A running Docker-compatible container engine, such as + [Docker](https://docs.docker.com/get-started/get-docker/) or + [Podman](https://github.com/knative/func/blob/main/docs/building-functions/podman.md){target=_blank}, + for containerized builders (`pack` or `s2i`). +- Run commands from inside the function project directory (or use `--path`). -- You have an initialized function project containing `func.yaml` and its source. - [Create a project](creating-functions.md) if needed. -- Docker is running for the container-based buildpacks builder used here. -- Run these commands from that project directory, not its parent directory. + -### Procedure +## Build -Set an explicit local image name so the build does not need a registry prompt: +Pass your registry: the registry host and your account namespace, for example +`ghcr.io/alice` or `docker.io/alice`: === "func" ```bash - func build --builder pack \ - --image localhost/my-function:latest + func build --registry ``` === "kn func" ```bash - kn func build --builder pack \ - --image localhost/my-function:latest + kn func build --registry ``` -`my-function` is an example image name; substitute yours consistently if desired. -`localhost` here is a local tag, not a registry server you must create. Wait for -building to complete, then check the image in Docker: +`func` names the image `/:latest` and saves the registry +in `func.yaml`, so later builds and deploys need no registry flag. You can also +set the registry with `FUNC_REGISTRY`. The image stays in your container engine's +local image store until you push it. If you previously set `--image`, see +[Set the image name yourself](#set-the-image-name-yourself) to return to registry-based naming. -```bash -docker image ls localhost/my-function:latest -``` - -A row with the tag `latest` and an image ID identifies the built image. This does -not mean it was pushed or started. For publishing, see the -[deployment guide](deploying-functions.md#procedure), which explains registry -prefixes and full image destinations. [Try Functions](../getting-started/about-knative-functions.md#run-and-test) -shows how to run and test an image as a separate step. For other builders, image -naming options, and flags, see the [func build reference](https://github.com/knative/func/blob/main/docs/reference/func_build.md). - -## On-cluster Builds - -This alternative uses a remote pipeline and deploys the resulting function. -It avoids a local container build, but requires a configured cluster and registry -credentials. The source can come from Git **or** direct upload; Git is not required -for the direct-upload branch. - -### Prerequisites - -- Your kubeconfig selects a cluster with Knative Serving installed. -- Tekton Pipelines and the function build pipeline are configured according to the - [on-cluster build setup guide](https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md). -- The pipeline can push to your chosen registry, and the cluster can pull the image. - Complete the registry/credential setup in that guide rather than assuming local - Docker login alone configures every remote pipeline. -- You have an initialized local function project and are in its directory. - -### Procedure - -Choose the source branch below. Replace `REGISTRY-USER` with your Docker Hub -account namespace in the image name. For Git, separately replace `GIT-OWNER` and -`GIT-REPO` with the repository owner and name; the Git owner need not match your -registry account. The explicit image destination avoids carrying over a local-only -tag from an earlier build. - -#### Git-backed source - -The function project must be committed in a Git repository the pipeline can read. -For a private repository, your platform administrator must provision pipeline -access before you use this branch; the linked function-build setup guide does -not provide a private-Git authentication recipe. The [Tekton authentication guide](https://tekton.dev/docs/pipelines/auth/) -is background for that platform setup. If you cannot arrange repository access, -use direct upload instead. - -These commands assume the project is at the repository root. For a subdirectory, -set `build.source.dir` in your project's `func.yaml` to its relative path, following -the configuration example in the [on-cluster build guide](https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md). -For example, `dir: functions/my-function` selects that directory within the Git repository. - -=== "func" +## Verify the image - ```bash - func deploy --remote \ - --image docker.io/REGISTRY-USER/my-function:latest \ - --git-url https://github.com/GIT-OWNER/GIT-REPO - ``` - -=== "kn func" +Confirm the image exists (with Podman, use `podman image ls`): - ```bash - kn func deploy --remote \ - --image docker.io/REGISTRY-USER/my-function:latest \ - --git-url https://github.com/GIT-OWNER/GIT-REPO - ``` +```bash +docker image ls / +``` -#### Direct-upload source +A row with tag `latest` and an image ID confirms the build succeeded. -Use this branch to upload the current local project. No Git repository is required. -Passing an empty Git URL explicitly clears a previously configured Git source. -If you previously set `build.source.dir` for a Git subdirectory, remove that `dir` -entry from `build.source` too so the upload uses the current local project root: + -=== "func" +## Other builders - ```bash - func deploy --remote \ - --image docker.io/REGISTRY-USER/my-function:latest \ - --git-url="" - ``` +`func build` supports `--builder pack` (Cloud Native Buildpacks, the default), +`--builder s2i` (Source-to-Image), and `--builder host`, which builds with your +local toolchain and needs no container engine. The `host` builder currently +supports Go and Python functions. It writes the image to `.func/build/oci` +in the project, not to the container engine, so `docker image ls` does not list it. -=== "kn func" +For remote on-cluster builds with Tekton, see +[Deploy a function — Build and deploy remotely](deploying-functions.md#build-and-deploy-remotely). +For all flags and builder options, see the +[`func build` reference](https://github.com/knative/func/blob/main/docs/reference/func_build.md){target=_blank}. - ```bash - kn func deploy --remote \ - --image docker.io/REGISTRY-USER/my-function:latest \ - --git-url="" - ``` +## Set the image name yourself -Wait for the pipeline and deployment to finish. Verify the **deployed** function -using `func invoke --target remote` (or `kn func invoke --target remote`) and -check your function's expected response. A finished image build alone does not -prove deployment or invocation succeeded. +To choose the full image name instead of `/:latest`, +pass `--image`, for example `--image ghcr.io/alice/my-image:v1`. `func` saves it +in the `image:` line in `func.yaml`, where it takes precedence over `--registry` +and `FUNC_REGISTRY` on later builds and deploys. To return to registry-based +naming, delete the `image:` line from `func.yaml`. diff --git a/docs/versioned/functions/creating-functions.md b/docs/versioned/functions/creating-functions.md deleted file mode 100644 index c34be4b926..0000000000 --- a/docs/versioned/functions/creating-functions.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -audience: developer -components: - - functions -function: how-to ---- - -# Creating functions - ---8<-- "create-a-function.md" diff --git a/docs/versioned/functions/deploying-functions.md b/docs/versioned/functions/deploying-functions.md index 62b578d60d..4e42bd8758 100644 --- a/docs/versioned/functions/deploying-functions.md +++ b/docs/versioned/functions/deploying-functions.md @@ -3,36 +3,143 @@ audience: developer components: - functions function: how-to +hide_prev: true +hide_next: true --- -# Deploying functions +# Deploy a function ---8<-- "deploy-func-intro.md" +Build, push, and deploy a function project to Kubernetes as a Knative Service +(or as a raw Kubernetes Deployment). For a guided first deployment, see +[Try Functions — Deploy to Knative](../getting-started/about-knative-functions.md#deploy-to-knative-optional). -## Prerequisites +## Requirements -- You have a Kubernetes cluster with Knative Serving installed, and your kubeconfig - selects the intended cluster and namespace. For a disposable environment, - [set up a learning cluster](../getting-started/quickstart-install.md) and check - its context before returning here. Local Functions development alone does not - create a cluster. +- An initialized function project containing `func.yaml` + ([create a project](running-functions.md#create-a-project) if needed). +- A Kubernetes cluster with Knative Serving installed, with your `kubectl` + context selecting the target cluster and namespace. +- Push access to a container registry that your cluster can pull from (use a + public repository or configure image pull secrets for private registries). +- For local builds: a running [Docker](https://docs.docker.com/get-started/get-docker/) + engine. For remote builds: Tekton Pipelines configured on the cluster. -- You have a Docker daemon running on your local machine for the container builder. - Quickstart uses an existing container engine; it does not install one. +## Deploy from your machine -- You have access to a container registry and are able to push images to this registry. Note that some image registries set newly pushed images to private by default. If you are deploying a function for the first time, you may need to ensure that your images are set to public. +Run `func deploy` from inside the project directory and pass your registry: the +registry host and your account namespace, for example `ghcr.io/alice` or +`docker.io/alice`. There is no need to run `func build` first. If you previously +passed `--image` (an exact image name), `func.yaml` keeps that name in an `image:` +line, which takes precedence over `--registry` until you delete the line. -## Procedure +=== "func" -For a first deployment, follow the [worked deployment tutorial](../getting-started/about-knative-functions.md#deploy-to-knative-optional), -which covers cluster setup, registry login, and the full image name. This is also -the next step if you are coming from the local Functions track. + ```bash + func deploy --registry + ``` -In the commands below, `` means the registry **and your account namespace**. -For example, `docker.io/alice` means Alice's Docker Hub namespace, and -`ghcr.io/alice` means her GitHub Container Registry namespace. Substitute your own -account; do not type the angle brackets. The CLI uses that prefix with the -function's project name to construct the image name. The worked tutorial instead -uses `--image` to set the complete destination explicitly. +=== "kn func" ---8<-- "proc-deploying-function.md" + ```bash + kn func deploy --registry + ``` + +`func` builds the image, pushes it to `/:latest`, and +creates or updates a Knative Service with the project name. + +- **Namespace:** By default, `func deploy` uses the previously deployed + namespace recorded in the project, or your current `kubectl` namespace on + first deploy. Pass `-n ` to target a specific namespace. +- **Private registries:** Set `FUNC_USERNAME` and `FUNC_PASSWORD` environment + variables for registry push credentials (avoid passing `--password` on the + command line), and ensure the target cluster namespace has pull credentials. +- **Raw Kubernetes deployer:** Add `--deployer raw` to deploy as a standard + Kubernetes Deployment and Service instead of a Knative Service. + +## Build and deploy remotely + +Use `--remote` to run the build and deployment on the cluster with Tekton +Pipelines instead of a local Docker engine. Configure Tekton and pipeline RBAC +first using the +[on-cluster build guide](https://github.com/knative/func/blob/main/docs/building-functions/on_cluster_build.md){target=_blank}. + +The following commands use the source flags introduced in `func` v1.24.0. +Before v1.24.0, `--source`, `--revision`, and `--source-dir` were named +`--git-url`, `--git-branch`, and `--git-dir`, respectively. + +Choose one source method (replace `REGISTRY-USER` with your registry account +namespace): + +=== "Git-backed source" + + Commit your project to a Git repository the cluster pipeline can read. For + private repositories, have your platform administrator provision pipeline + Git access first (see the + [Tekton authentication guide](https://tekton.dev/docs/pipelines/auth/){target=_blank}). + If the project is in a subdirectory, add `--source-dir `. + To select a branch, tag, or commit, add `--revision `. + + ```bash + func deploy --remote \ + --registry docker.io/REGISTRY-USER \ + --source https://github.com/GIT-OWNER/GIT-REPO + ``` + + With an explicit `--source`, `func` deploys the function by reference from + the repository and does not write to the local `func.yaml`. Do not combine + `--source` with `--image`; use `--registry` instead. Re-run the same command + with `--source` for subsequent Git-backed deployments. + +=== "Direct upload (no Git)" + + Upload the current local project directory directly. Passing `--source=""` + and `--source-dir=""` clears any previously configured Git repository and + subdirectory: + + ```bash + func deploy --remote \ + --registry docker.io/REGISTRY-USER \ + --source="" --source-dir="" + ``` + +(`kn func deploy` accepts the same flags.) + +## Verify + +Invoke the deployed function with an explicit `--target remote` so you do not +accidentally hit a locally running instance: + +=== "func" + + ```bash + func invoke --target remote + ``` + +=== "kn func" + + ```bash + kn func invoke --target remote + ``` + +Confirm the response body matches your function's expected output. You can also +check status on the cluster: + +- **Knative deployer (default):** `kn service describe -n ` +- **Raw deployer (`--deployer raw`):** `kubectl get deployment/ service/ -n ` + +## Update and remove + +- **Update:** + - Local builds and direct-upload remote builds: edit your code and re-run + `func deploy` (or `func deploy --remote --source="" --source-dir=""`). + - Git-backed remote builds: commit and push your changes to the Git + repository first, then re-run the same `func deploy --remote --source ...` + command, including any `--revision` and `--source-dir` flags. + - With the default Knative deployer, each deploy rolls out a new Revision; + with `--deployer raw`, it updates the Kubernetes Deployment. +- **Remove:** Run `func delete` from inside the project directory (works for + both Knative and raw deployers). You can also delete directly with + `kn service delete -n ` (Knative deployer) or + `kubectl delete deployment/ service/ -n ` (raw + deployer). Deleting the workload does not delete the pushed image from your + container registry. diff --git a/docs/versioned/functions/install-func.md b/docs/versioned/functions/install-func.md deleted file mode 100644 index ad5aca0330..0000000000 --- a/docs/versioned/functions/install-func.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -audience: developer -components: - - functions -function: how-to ---- - -# Installing Knative Functions - ---8<-- "install-functions-intro.md" - -## Installing the `func` CLI - ---8<-- "install-func-CLI.md" - -## Installing the `kn func` CLI plugin - ---8<-- "install-kn-func-plugin.md" diff --git a/docs/versioned/functions/invoking-functions.md b/docs/versioned/functions/invoking-functions.md deleted file mode 100644 index da8d92b930..0000000000 --- a/docs/versioned/functions/invoking-functions.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -audience: developer -components: - - functions -function: how-to ---- - -# Invoking functions - -You can use the `func invoke` command to send a test request to invoke a -function either locally or on your Knative cluster. - -This command can be used to test that a function is working and able to receive HTTP requests and CloudEvents correctly. - -If your function is running locally, `func invoke` sends a test request to the local instance. - -You can use the `func invoke` command to send test data to your function with the `--data` flag, as well as other options to simulate different types of requests. See the [func invoke](https://github.com/knative/func/blob/main/docs/reference/func_invoke.md){target=_blank} documentation for more information. diff --git a/docs/versioned/functions/kafka-functions.md b/docs/versioned/functions/kafka-functions.md deleted file mode 100644 index 66cbcbef7b..0000000000 --- a/docs/versioned/functions/kafka-functions.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -audience: developer -components: - - functions -function: explanation ---- - -# Kafka functions - -A function can consume messages from an Apache Kafka topic. When a function declares a `run.kafka` configuration, `func` deploys a language-agnostic runtime sidecar alongside it. The sidecar consumes the topic and delivers each record to the function as a CloudEvent over HTTP, so the function stays a plain CloudEvents handler in any language, with no Kafka client code of its own. - -The full guide lives in the `func` repository, covering concepts, a getting-started walkthrough, delivery and retries, deployment and scaling, idempotency, local development, and troubleshooting: - -- [Kafka functions guide](https://github.com/knative/func/blob/main/docs/kafka-functions/README.md){target=_blank} -- [run.kafka configuration reference](https://github.com/knative/func/blob/main/docs/reference/func_yaml.md#runkafka){target=_blank} diff --git a/docs/versioned/functions/language-packs.md b/docs/versioned/functions/language-packs.md index 0322039ed8..431011aee5 100644 --- a/docs/versioned/functions/language-packs.md +++ b/docs/versioned/functions/language-packs.md @@ -3,19 +3,84 @@ audience: developer components: - functions function: how-to +hide_prev: true +hide_next: true --- -# Language packs +# Templates and runtimes -Language packs can be used to extend Knative Functions to support additional runtimes, function signatures, operating systems, and installed tooling for functions. Language Packs are distributed through Git repositories or as a directory on a disc. +Knative Functions includes built-in language runtimes and templates, and lets +you pull custom templates from Git repositories via language packs. -For more information see the [language pack](https://github.com/knative/func/blob/main/docs/language-packs/language-pack-contract.md){target=_blank} documentation. +## Choose a runtime -## Using external Git repositories +Pass `-l ` to `func create`. Built-in runtimes: -When creating a new function, a Git repository can be specified as the source -for the template files. +| Runtime | `-l` value | +| --- | --- | +| Go | `go` | +| Node.js | `node` | +| TypeScript | `typescript` | +| Python | `python` | +| Quarkus (Java) | `quarkus` | +| Spring Boot (Java) | `springboot` | +| Rust | `rust` | -## Installing language packs locally +## Choose HTTP or CloudEvents -Language packs can be installed locally by using the [`func repository`](https://github.com/knative/func/blob/main/docs/reference/func_repository.md){target=_blank} command. +Pass `-t