×
Community Blog Use ASM to Manage Knative Services (2): Use Knative on ASM to Deploy Serverless Applications

Use ASM to Manage Knative Services (2): Use Knative on ASM to Deploy Serverless Applications

Part 2 of this 6-part series describes how to use Knative on ASM to create Knative services.

By Xining Wang

Article Series

Use ASM to Manage Knative Services (1): An Overview of Knative on ASM

Use ASM to Manage Knative Services (2): Use Knative on ASM to Deploy Serverless Applications

Use ASM to Manage Knative Services (3): Use Custom Domain in Knative on ASM

Use ASM to Manage Knative Services (4): Use ASM Gateway to Access Knative Services over HTTPS

Use ASM to Manage Knative Services (5): Canary Deployment of Services Based on Traffic in Knative on ASM

Use ASM to Manage Knative Services (6): Auto Scaling Based on the Number of Traffic Requests

Prerequisites

  • Create at least one ASM instance whose version is 1.16 or later. Add at least one ACK cluster or ASK cluster to the instance. Please visit Create an ASM Instance and Add a Cluster to an ASM Instance for more information.
  • Deploy Knative Serving components:

    • Please visit Deploy Knative if you want to deploy Knative in an ACK cluster.
    • Please visit Turn on Knative if you want to deploy Knative in an ASK cluster.
  • Add ingress gateway to the cluster. In this instance, an ASM ingress gateway is used as the cluster gateway. Please visit Add an Ingress Gateway Service for more information.

ASM Gateway provides Knative with Knative Revisions traffic distribution and supports functions, including gRPC services, timeout and retry, TLS certificates, and external authentication and authorization. Please visit this link for more information.

Enable Knative on ASM Function

Log on to the ASM console. On the left-side navigation pane, choose Service Mesh > Mesh Management. On the Mesh Management page, click the name of the instance you want to manage. Then, on the left-side navigation pane, choose Ecological Integration > Knative on ASM. On the page that appears on the right, click Enable. It can be opened later after the update is completed.

  1. Log on to the ASM console. On the left-side navigation pane, choose Service Mesh > Mesh Management
  2. On the Mesh Management page, click the name of the ASM instance. On the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

Deploy Knative Services

You can use the Container Service management console or YAML configuration file to deploy Knative services. You can choose whichever is right for you.

Method 1: Deploy Knative Services Using the Container Service Management Console

  1. You can log on to the Container Service management console and choose Cluster in the left-side navigation pane.
  2. On the Cluster list page, click the name of the cluster you want to manage and choose Applications > Knative on the left-side navigation pane
  3. On the Services tab, click Create Service in the upper-right corner to set the required parameters and then click Create.
Parameter Description
Namespace Select the namespace to which the Service belongs
Service Name Enter a name for the Service
ImageName Click Select Image to select an image. In the dialog box that appears, select an image and click OK. You can also enter the address of a private image registry. The registry 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 Click Select Image Version to select an image version. In this example, the image version is 73fbdd56.
Access Protocol HTTP and gRPC are supported.
Container Port Set the container port 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 Number of 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 Number of Instances to be Scaled in Set the minimum number of instances that must be kept running when no request is received. If you set this parameter to 0, it means the number of running instances is reduced to zero when no request is received.
Maximum Number of Instances to be Scaled out Set the maximum number of instances that are allowed to be scaled out
Limits on Resources 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 Management The lifecycle contains Command and Args and the configuration instructions are listed below:
If you do not configure the Command and Args, the default command and Args of the image are used.
If you only configure Args, the default command of the image and the newly configured Args are used.
If you configure both of them, the default image configurations will be overwritten by the new ones.
Environment Variables Set environment variables in key-value pairs
Volumes You can mount local storage volumes and persistent volume claims (PVCs) to the container.
Local Storage: You can select HostPath, ConfigMap, Secret, or EmptyDir. The specified volume is mounted to a path in the container. Please see Volumes for more information.
PVC: Support Cloud Storage.

Note: After the Service is created, you can view, modify, or delete the Service on the Services tab.

Method 2: Deploy Knative Services Using the YAML Configuration File

1.  Save the following content as hello.yaml:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  annotations:
    knative.k8s.alibabacloud/tls: "false" 
spec:
  template:
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/acs/helloworld-go:160e4dc8
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "Knative"

2.  Use kubectl to connect to the cluster and run the following command to create a Knative Service:

kubectl apply -f hello.yaml

3.  Wait for a while and execute the following command to view the list of Knative services:

kubectl get ksvc

Expected output:

NAME            URL                                        LATESTCREATED         LATESTREADY           READY   REASON
helloworld-go   http://helloworld-go.default.example.com   helloworld-go-00001   helloworld-go-00001   True

Access Services

After the Knative service is created, you can access the service address by binding the Host domain name with the access gateway. Perform the following steps to access the service address:

1.  On the Services tab, click the Service Name or click Details in the Action Bar to go to the Knative service details page. In the Basic Information section, you can view information about the access gateway and domain name.

1

2.  Add the following information to the host file to point the domain name of the Service to the IP address of the gateway. The binding sample is listed below (replace xx.xx.xxx.xx with your gateway IP):

xx.xx.xxx.xx helloworld-go.default.example.com

3.  After Host is bound, you can use the domain name to access the Knative Service:

curl http://helloworld-go.default.example.com
Hello Knative!

2

0 0 0
Share on

Xi Ning Wang(王夕宁)

56 posts | 8 followers

You may also like

Comments

Xi Ning Wang(王夕宁)

56 posts | 8 followers

Related Products