Deploying functions¶
Deploying a function creates an OCI container image for your function, and pushes this container image to your image registry. The function is deployed to the cluster as a Knative Service. Redeploying a function updates the container image and resulting Service that is running on your cluster. Functions that have been deployed to a cluster are accessible on the cluster just like any other Knative Service.
Prerequisites¶
-
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 and check its context before returning here. Local Functions development alone does not create a 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.
-
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.
Procedure¶
For a first deployment, follow the worked deployment tutorial, 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.
In the commands below, <registry> 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.
The deploy command uses the function project name as the Knative Service name. When the function is built, the project name and the image registry name are used to construct a fully qualified image name for the function.
Deploy the function by running the command inside the project directory:
func deploy --registry <registry>
Deploy the function by running the command inside the project directory:
kn func deploy --registry <registry>
Note
In case you want to deploy your function as a raw Kubernetes Deployment and Service instead of a Knative Service, you can use the raw deployer:
Deploy the function by running the command inside the project directory:
func deploy --registry <registry> --deployer raw
Deploy the function by running the command inside the project directory:
kn func deploy --registry <registry> --deployer raw
Expected output
🙌 Function image built: <registry>/hello:latest
✅ Function deployed in namespace "default" and exposed at URL:
http://hello.default.127.0.0.1.sslip.io
Private Registry Authentication
For private registries that require authentication, you can set credentials using environment variables:
FUNC_USERNAME: The username for registry authenticationFUNC_PASSWORD: The password for registry authentication
These variables work with all builders: host, s2i, and pack.
Note: Using environment variables is more secure than the --password flag because command-line arguments are visible to all users on the system via ps.
Verify the deployed function with an explicit remote target, even if a local
function is also running. The response should contain your function's expected
output; deployment readiness alone does not prove you called the remote instance:
func invoke --target remote
kn func invoke --target remote
The response format varies by template. For example:
Example response
Received response
POST / HTTP/1.1 hello.default.127.0.0.1.sslip.io
User-Agent: Go-http-client/1.1
Content-Length: 25
Accept-Encoding: gzip
Content-Type: application/json
K-Proxy-Request: activator
X-Request-Id: 9e351834-0542-4f32-9928-3a5d6aece30c
Forwarded: for=10.244.0.15;proto=http
X-Forwarded-For: 10.244.0.15, 10.244.0.9
X-Forwarded-Proto: http
Body: