All Products
Search
Document Center

Container Compute Service:Deploy Knative Functions based on Knative

Last Updated:Mar 26, 2026

Knative Functions lets you create, build, and deploy functions on Knative without managing Kubernetes or container infrastructure. After you scaffold a function project, the system builds a container image automatically and deploys it as a Knative Service.

Prerequisites

Before you begin, ensure that you have Knative deployed in your ACS cluster. See Deploy Knative.

Step 1: Install the func CLI

Download the func binary from the func releases page 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 func to a directory on your PATH so it can be run from anywhere:

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

    func version

    If version information is returned, the installation is complete.

Step 2: Create a function

Knative Functions supports the following runtimes for both HTTP and CloudEvent invocations:

Runtime Template reference
Node.js nodejs.md
Python python.md
Go golang.md
Quarkus quarkus.md
Rust rust.md
Spring Boot springboot.md
TypeScript typescript.md

The following example creates a Go function named hello:

  1. Scaffold the function project:

    func create -l go hello

    Expected output:

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

    func.yaml  go.mod  handle.go  handle_test.go  README.md
  3. View the auto-generated func.yaml:

    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 image registry and deployment namespace. The following example shows a customized configuration:

    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
    Field Description
    registry The container registry where the built image is pushed
    builderImages The builder image used to build the function. Example: registry-cn-beijing.ack.aliyuncs.com/acs/knative-func-builder-jammy-tiny:latest
    deploy Deployment configuration, including the namespace where the function is deployed

    For all available fields, see func_yaml.md.

Step 3: Deploy the function

Run the following command from inside the hello directory:

func deploy

The deploy command builds the container image, pushes it to the registry specified in func.yaml, and deploys the function as a Knative Service. The service name matches the function project name, and the full image address is generated from the project name and registry.

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

To verify the deployment, run:

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 the HTTP request reached Knative Functions and the function was invoked successfully.

  3. Confirm that pods were created after invocation:

    kubectl get pod

    Expected output:

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

What's next

For common issues and solutions when using Knative, see Knative FAQ.