Quickly deploy a Knative service

更新时间:
复制 MD 格式

Deploy your workloads as a Knative service for use cases such as web hosting, serverless applications, AI tasks, and event-driven architectures. A Knative service lets you use resources on demand and focus on your business logic. It provides features like request-based auto scaling, scaling to zero pods when idle, and simplified revision management.

Prerequisites

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

Step 1: Deploy a Knative service

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

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Knative.

  3. Click the Services tab. At the top of the Services page, select the namespace for the service. Then, deploy the Knative service.

    You can deploy the service from the console or by using YAML.

    Console

    In the upper-right corner of the Services page, click Create Service and configure the parameters.

    Parameter

    Description

    Service name

    Enter a custom name for the service.

    Image name

    Click Select Image and choose an image from the dialog box.

    You can also specify a private image and tag. The format is domainname/namespace/imagename:tag.

    You can also use the demo image and version provided by ACK as prompted on the page. This example uses registry-vpc.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56 (replace the region cn-hangzhou with your actual region).

    Set Image Pull Secret

    Credentials used to pull private images.

    Access Protocol

    The supported protocols are HTTP and gRPC.

    Container port

    The port on the container that listens for network traffic. The port number must be between 1 and 65535.

    Advanced

    Click Advanced Settings to configure more settings.

    Expand to view advanced parameters

    • Internal Access Only: If selected, the service is accessible only from within the cluster.

    • Maximum Concurrent Requests: The maximum number of concurrent requests per pod. A default value of 0 means no limit.

    • The custom domain name for the service.

    • Minimum Pods: The minimum number of pods to keep running, even when idle. If set to 0, the service can scale to zero pods.

    • Maximum Pods: The maximum number of pods for the service.

    • Limit: The maximum resources that the application can use. This prevents a single application from consuming too many resources. You can set limits for CPU (in cores), memory (in bytes or MiB), and GPUs.

    • Lifecycle: The container's startup command (Command) and arguments (args).

      • If you leave both fields empty, the defaults from the container image are used.

      • If you only specify args, the image's default command is used with the specified args.

      • If you specify both, they override the image's default command and args.

    • Environment Variable: Environment variables for the container, specified as key-value pairs.

    • Volumes: Supports local storage and persistent volume claims (PVCs).

      • Local storage: Supports hostPath, ConfigMap, Secret, and emptyDir. These volumes mount a source from the host or cluster to a path inside the container. For more information, see the official Kubernetes documentation about Volumes.

      • Persistent volume claim (PVC): Supports cloud storage.

    YAML

    1. In the upper-right corner of the Services page, click Create from Template.

    2. In the editor, paste your YAML manifest and click Create.

      For example, paste the following YAML into the template to create a service named helloworld-go.

      apiVersion: serving.knative.dev/v1
      kind: Service
      metadata:
        name: helloworld-go
      spec:
        template:
          spec:
            containers:
            - image: registry-vpc.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56  # Replace with your region ID.
              env:
              - name: TARGET
                value: "Knative"

    After the service is created, it appears on the Services tab. From here, you can view, edit, or delete the service.

Step 2: Access the service

After the Knative service is created, you can access it by mapping the service's domain name to the gateway IP address in your local hosts file.

  1. On the Services tab, click the service name.

    In the Basic Information section of the details page, find the access gateway and domain name.

  2. Add an entry to your local hosts file to map the gateway IP address to the domain name.

    The following example shows the format.

    121.xx.xxx.xx helloworld-go.default.example.com
  3. Access the service in your browser by using its domain name.访问服务

Related topics

  • For more information about how to use a custom domain name for your Knative service, see Use a custom domain and path.

  • For more information about how to configure an HTTPS certificate for your Knative service, see Configure an HTTPS certificate.

  • For more information about how to create a revision to manage different versions of your Knative service, see Create a revision.

  • If your workload experiences unpredictable traffic spikes, you can deploy the Knative service by using Elastic Container Instance (ECI) resources. For more information, see Use Elastic Container Instance resources.

  • For more information about how to implement request-based auto scaling for your Knative service, see Implement request-based auto scaling.

  • For more information about how to deploy Knative Eventing and create event-driven workloads, see Knative Eventing.