All Products
Search
Document Center

Container Service for Kubernetes:Use Knative Eventing to send messages

Last Updated:Apr 30, 2025

Knative is an open-source platform based on Kubernetes that orchestrates serverless applications. Container Service for Kubernetes (ACK) extends Knative with event-driven architecture and auto-scaling capabilities while maintaining full compatibility with the open-source Knative. This topic uses a live comment service to demonstrate how to implement live comment delivery through Knative.

Prerequisites

Knative Eventing is deployed.

Step 1: Deploy a message processing Service and a home page

The message processing Service handles live comment requests and scales automatically based on demand. The home page facilitates the sending and receiving of live comments. Use the following steps to deploy these two Services:

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

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

  3. On the Knative page, click the Services tab, then click Create from Template.

    The following YAML template creates a Service named danmu-message. Replace the image field in the example code with one that corresponds to the region of your cluster. This example uses the China (Beijing) region.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: danmu-message
      namespace: default
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/maxScale: "10"
            autoscaling.knative.dev/minScale: "1"
        spec:
          containerConcurrency: 2
          containers:
            - args:
                - /message
                - --url=http://danmu-portal.default.svc.cluster.local/api/result
              env:
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
              image: registry-vpc.cn-beijing.aliyuncs.com/acs/knative-danmu-message:v1.0
              name: user-container
              ports:
                - containerPort: 8080
                  name: http1
  4. Repeat the previous step. Clear the template content, paste the following YAML template to create a homepage, and click Create.

    The following YAML template creates a Service named danmu-portal. Replace the image field specified in the sample code with one that corresponds to the region of the cluster.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: danmu-portal
      namespace: default
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/maxScale: "1"
            autoscaling.knative.dev/minScale: "1"
        spec:
          containers:
            - image: registry-vpc.cn-beijing.aliyuncs.com/acs/knative-danmu-portal:v1.0
              name: user-container
              args:
              - /danmu
              - --url=http://danmu-message.default.svc.cluster.local/web/api/process
              ports:
                - containerPort: 8080
                  name: http1
  5. On the Services tab, when both danmu-message and danmu-portal display a Created state, the Services are deployed successfully.

    Record the IP address of the Gateway for use in the following step.

Step 2: Bind the gateway address and domain name

After deploying the message processing Service and homepage, bind the recorded gateway address to the domain name of the homepage, danmu-portal.default.example.com. This domain name is used for sending and receiving live comments.

To access the Service through the domain name, locate the Hosts file on your computer and add the binding information. The binding information is in the following format: <gateway IP>, followed by a space and the domain name. For example, 47.96.XX.XX danmu-portal.default.example.com.

Step 3: Deploy the Service

Enter the domain name http://danmu-portal.default.example.com into your browser to access the live comment service. Configure the following parameters on the page and click Send to view live comments. You can also monitor the extracted pod information in the pod list.

Parameter

Description

Example

Message

The live message to be sent.

welcome

Concurrency

The number of concurrent live messages.

20

Duration

The duration of live messages in seconds.

30