Deploy a function¶
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.
Requirements¶
- An initialized function project containing
func.yaml(create a project if needed). - A Kubernetes cluster with Knative Serving installed, with your
kubectlcontext 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 engine. For remote builds: Tekton Pipelines configured on the cluster.
Deploy from your machine¶
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.
func deploy --registry <registry>
kn func deploy --registry <registry>
func builds the image, pushes it to <registry>/<project-name>:latest, and
creates or updates a Knative Service with the project name.
- Namespace: By default,
func deployuses the previously deployed namespace recorded in the project, or your currentkubectlnamespace on first deploy. Pass-n <namespace>to target a specific namespace. - Private registries: Set
FUNC_USERNAMEandFUNC_PASSWORDenvironment variables for registry push credentials (avoid passing--passwordon the command line), and ensure the target cluster namespace has pull credentials. - Raw Kubernetes deployer: Add
--deployer rawto 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.
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):
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).
If the project is in a subdirectory, add --source-dir <subdirectory>.
To select a branch, tag, or commit, add --revision <revision>.
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.
Upload the current local project directory directly. Passing --source=""
and --source-dir="" clears any previously configured Git repository and
subdirectory:
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 invoke --target remote
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 <function-name> -n <namespace> - Raw deployer (
--deployer raw):kubectl get deployment/<function-name> service/<function-name> -n <namespace>
Update and remove¶
- Update:
- Local builds and direct-upload remote builds: edit your code and re-run
func deploy(orfunc 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--revisionand--source-dirflags. - With the default Knative deployer, each deploy rolls out a new Revision;
with
--deployer raw, it updates the Kubernetes Deployment.
- Local builds and direct-upload remote builds: edit your code and re-run
- Remove: Run
func deletefrom inside the project directory (works for both Knative and raw deployers). You can also delete directly withkn service delete <function-name> -n <namespace>(Knative deployer) orkubectl delete deployment/<function-name> service/<function-name> -n <namespace>(raw deployer). Deleting the workload does not delete the pushed image from your container registry.