All Products
Search
Document Center

Container Service for Kubernetes:Use Knative to quickly deploy serverless applications

Last Updated:Sep 01, 2023

This topic describes how to use Knative to quickly deploy a serverless application. In this topic, a Hello World application is used as an example.

Prerequisites

Step 1: Deploy a Knative Service

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Knative in the left-side navigation pane.

  3. On the Services tab, click Create Service in the upper-right corner, set the required parameters, and then click Create.
    ParameterDescription
    NamespaceSelect the namespace to which the Service belongs.
    Service NameEnter a name for the Service.
    Image Name

    To select an image, click Select Image. In the Select Image dialog box, select an image and click OK. You can also enter the address of a private image registry. The address must be in the domainname/namespace/imagename:tag format. In this example, registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go is used.

    Image Version

    To select an image version, click Select Image Version. In this example, the image version is 73fbdd56.

    Access Protocol

    HTTP and gRPC are supported.

    Container Port

    Set the container port that you want to expose. The port number must be in the range of 1 to 65535.

    Internal Access Only

    If you select Internal Access Only, the Knative Service cannot be accessed over the Internet.

    Maximum Concurrent Requests

    Set the maximum number of concurrent requests supported by the container. The default value is 0. This indicates that the number of concurrent requests is unlimited.

    Minimum Pods

    Set the minimum number of pods that must be kept running when no request is received. If you set this parameter to 0, the number of running pods is reduced to zero when no request is received.

    Maximum Pods

    Set the maximum number of pods that are allowed to run.

    Resource Limit

    Set the maximum amount of CPU, memory, and GPU resources that can be allocated to the Knative Service. This prevents the Service from occupying an excessive amount of resources. CPU usage is measured in cores. Memory usage is measured in bytes or mebibytes.

    Lifecycle
    You can set the Command and Parameter parameters. Take note of the following limits:
    • If Command and Parameter are not set, the default values of Command and Parameter in the image configurations are used.
    • If you set only Parameter, the default value of Command in the image configurations and the specified value of Parameter are used.
    • If you set both Command and Parameter, the default values of Command and Parameter in the image configurations are overwritten by the specified values.
    Environment Variables

    Set environment variables in key-value pairs.

    VolumeYou can mount local storage volumes and persistent volume claims (PVCs) to the container.
    • Add Local Storage: You can select HostPath, ConfigMap, Secret, or EmptyDir. The specified volume is mounted to a path in the container. For more information, see Volumes.
    • Add PVC: Select Cloud Storage.
    Note After the Service is created, you can view, modify, or delete the Service on the Services tab.

Step 2: Access the Knative Service

  1. On the Services tab, click the name of the Service.
    In the Basic Information section, you can view information about the access gateway and domain name. The Knative Service
  2. Add the following information to the hosts file to point the domain name of the Service to the IP address of the gateway.
    Example:
    121.xx.xxx.xx helloworld-go.default.example.com
  3. After you modify the hosts file, you can use the domain name to access the Knative Service. Access the Service