All Products
Search
Document Center

Container Service for Kubernetes:Deploy Knative Functions based on Knative

Last Updated:Oct 14, 2026

Knative Functions provides a simplified programming model for creating and deploying functions on Knative, hiding many underlying details of Knative, Kubernetes, and containers. You create a function and the system automatically generates the container image. After you customize the parameters for image building and deployment, you can deploy the function as a Knative Service.

Prerequisites

Knative is deployed in your cluster. For more information, see Deploy and manage Knative components.

Step 1: Install the command-line tool

  1. On the func release page, download the func binary file for your operating system.

    This topic uses Linux as an example to show how to install the func command-line tool.

  2. After the download is complete, run the following command to rename the binary file to func.

    mv <path-to-binary-file> func # <path-to-binary-file> indicates the local path of the binary file, for example, func_darwin_amd64 or func_linux_amd64.
  3. Run the following command to grant executable permissions on the binary file.

    chmod +x func
  4. Run the following command to move the func command to a directory in the system PATH so that you can run the command from anywhere.

    mv func /usr/local/bin
  5. Run the following command to verify that the func command-line tool is installed.

    func version

    If the version information of the installed func tool is displayed, the command-line tool is installed.

Step 2: Create a function

Knative Functions provides templates for multiple languages and invocation methods. The following templates are available for CloudEvent and HTTP invocations.

The following example uses the Go template to show how to create a function.

  1. Run the following command to create a function.

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

    For example, create a sample function in Go.

    func create -l go hello

    Expected output:

    Created go function in /usr/local/bin/hello
  2. In the hello directory, run the ls command to view the created project directory.

    func.yaml  go.mod  handle.go  handle_test.go  README.md
  3. In the hello directory, run the following command to view the automatically created func.yaml file.

    cat func.yaml

    Expected output:

    specVersion: 0.35.0
    name: hello
    runtime: go
    created: 2023-12-13T06:48:45.419587147Z
  4. Edit the func.yaml file to customize the parameters for building and deployment for later use. The func.yaml file contains the configuration information of the function project. For details, see func_yaml.md.

    The following is a sample func.yaml file:

    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
    • registry: the target repository address to which the image is pushed after the build.

    • builderImages: the container used for image building, for example, registry-cn-beijing.ack.aliyuncs.com/acs/knative-func-builder-jammy-tiny:latest.

    • deploy: the deployment-related configurations, such as the namespace.

Step 3: Deploy Knative Functions

After you create a function, you can deploy Knative Functions directly.

  1. Run the following command to deploy the function in the function project.

    deploy uses the function project name as the Knative Service name by default. When the function is built, the project name and the image repository name are used to construct the full image address of the function.

    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
  2. Run the following command to view function deployment information.

    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 Knative Functions

  1. Map the Knative access gateway address to the domain name that you want to access by adding an entry to the hosts file.

    The following is a sample binding.

    121.xx.xxx.xx hello.default.example.com # 121.xx.xxx.xx: replace it with the gateway address of the Knative Service, and replace hello.default.example.com with your service domain name.
  2. Run the following command to 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 expected output indicates that an HTTP request was sent to Knative Functions and the function invocation succeeded.

  3. Run the following command to view the status of the pods in the cluster.

    kubectl get pod

    Expected output:

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

    The expected output indicates that the function invocation triggered the creation of a pod.

References

For common issues that you may encounter when using Knative and their solutions, see Knative FAQ.