All Products
Search
Document Center

Container Service for Kubernetes:Deploy Knative Functions

Last Updated:Mar 26, 2026

Knative Functions provides a simplified programming model for creating and deploying serverless functions on Knative. You write the function code, and Knative Functions automatically builds a container image and deploys it as a Knative Service — no Kubernetes or container expertise required.

Prerequisites

Before you begin, make sure you have:

Step 1: Install the func CLI

Download the func binary from the func release page and select the binary for your operating system.

The following example installs func on Linux:

  1. Rename the binary to func:

    mv <path-to-binary-file> func

    Replace <path-to-binary-file> with the path to the downloaded binary, for example, func_linux_amd64.

  2. Make the binary executable:

    chmod +x func
  3. Move the binary to a directory in your PATH:

    mv func /usr/local/bin
  4. Verify the installation:

    func version

    If version information is returned, func is installed successfully.

Step 2: Create a function

Knative Functions supports the following runtimes, all of which work with both HTTP and CloudEvent invocations:

The following steps use Go as an example.

  1. Create a function:

    func create -l <language> <function-name>

    For example, create a Go function named hello:

    func create -l go hello

    Expected output:

    Created go function in /usr/local/bin/hello
  2. List the project files in the hello directory:

    ls hello/

    Expected output:

    func.yaml  go.mod  handle.go  handle_test.go  README.md
  3. Review the auto-generated func.yaml in the hello directory:

    cat func.yaml

    Expected output:

    specVersion: 0.35.0
    name: hello
    runtime: go
    created: 2023-12-13T06:48:45.419587147Z
  4. Edit func.yaml to configure the registry and deployment settings. The following is an example of a complete func.yaml:

    specVersion: 0.35.0
    name: hello
    runtime: go
    created: 2023-11-29T14:47:34.101658+08:00
    registry: registry.cn-beijing.aliyuncs.com/knative-release-xxx
    image: registry.cn-beijing.aliyuncs.com/knative-release-xxx/hello:latest
    build:
      builderImages:
        pack: registry-cn-beijing.ack.aliyuncs.com/acs/knative-func-builder-jammy-tiny:latest
    deploy:
      namespace: default

    Key fields:

    Field Description
    registry The container registry where built images are pushed. Example: registry.cn-beijing.aliyuncs.com/knative-release-xxx
    build.builderImages.pack The builder image used to build the function. Example: registry-cn-beijing.ack.aliyuncs.com/acs/knative-func-builder-jammy-tiny:latest
    deploy.namespace The Kubernetes namespace where the function is deployed

Step 3: Deploy the function

Run func deploy from inside the hello directory. The command uses the function project name as the Knative Service name and combines the project name with the registry to construct the full image address.

func deploy

Expected output

Building function image
Still building
Still building
Yes, still building
Don't give up on me
Still building
This is taking a while
Still building
Still building
Yes, still building
Function built: registry.cn-beijing.aliyuncs.com/knative-release-xxx/hello:latest
Pushing function image to the registry "registry.cn-beijing.aliyuncs.com" using the "xxx" user credentials
Deploying function to the cluster
Function deployed in namespace "default" and exposed at URL:
   http://hello.default.example.com

After deployment, verify the function details:

func info

Expected output:

Function name:
  hello
Function is built in image:

Function is deployed in namespace:
  default
Routes:
  http://hello.default.example.com

Step 4: Invoke the function

  1. Add an entry to your hosts file to route the Knative Service domain name to the Knative gateway IP address:

    121.xx.xxx.xx hello.default.example.com

    Replace 121.xx.xxx.xx with the actual Knative gateway IP address and hello.default.example.com with the domain name shown in the deployment output.

  2. Invoke the function:

    func invoke

    Expected output:

    POST / HTTP/1.1 hello.default.example.com
      Content-Type: application/json
      Forwarded: for=192.168.102.101;proto=http
      Knative-Serving-Default-Route: true
      X-Forwarded-Proto: http
      User-Agent: Go-http-client/1.1
      Content-Length: 25
      Accept-Encoding: gzip
      K-Proxy-Request: activator
      X-Forwarded-For: 192.168.102.101, 192.168.102.97
      X-Request-Id: 3d82cfc8-f9df-4935-84cd-c6561b4587f6
    Body:

    The output confirms that an HTTP request was successfully sent to and handled by the function.

  3. Verify that pods were created for the function:

    kubectl get pod

    Expected output:

    NAME                                      READY   STATUS    RESTARTS   AGE
    hello-00001-deployment-7b65fcdc4c-gfcbp   2/2     Running   0          34

What's next

For answers to common questions about Knative in ACK, see Knative FAQ.