All Products
Search
Document Center

Container Service for Kubernetes:Deploy Knative Functions

Last Updated:Jun 25, 2026

Knative Functions provides a simplified programming model for creating and deploying functions on Knative, abstracting Knative, Kubernetes, and container details. Create your function, let the platform build the container image, customize image build and deployment settings, and deploy it as a Knative Service.

Prerequisites

Make sure you have:

Step 1: Install the func CLI

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

Example for Linux:

  1. Rename the binary to func:

    mv <path-to-binary-file> func

    Replace <path-to-binary-file> with the downloaded binary path, such as 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

    Version output confirms successful installation.

Step 2: Create a function

Knative Functions supports the following runtimes, all compatible with HTTP and CloudEvent invocations:

This example uses Go.

  1. Create a function:

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

    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 files in the hello directory:

    ls hello/

    Expected output:

    func.yaml  go.mod  handle.go  handle_test.go  README.md
  3. Review the 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. Complete example:

    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 Container registry for built images. Example: registry.cn-beijing.aliyuncs.com/knative-release-xxx
    build.builderImages.pack Builder image for the function. Example: registry-cn-beijing.ack.aliyuncs.com/acs/knative-func-builder-jammy-tiny:latest
    deploy.namespace Target Kubernetes namespace for the function.

Step 3: Deploy the function

Run func deploy from the hello directory. The command uses the project name as the Knative Service name and combines it with the registry to construct the 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

Verify the deployment:

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 a hosts file entry to map the Knative Service domain to the gateway IP:

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

    Replace 121.xx.xxx.xx with your Knative gateway IP and hello.default.example.com with your deployment domain.

  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 the function received and handled the HTTP request.

  3. Verify that function pods were created:

    kubectl get pod

    Expected output:

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

Next steps

See Knative FAQ for common questions about Knative in ACK.