If your business traffic spikes unexpectedly, you can use pods deployed on elastic container instances in Knative. This allows you to pay for resources based on the actual usage.
Prerequisites
Knative is deployed in your cluster. For more information, see Deploy Knative.
The ack-virtual-node component is deployed. This component is required when you use elastic container instances. For more information, see Deploy ack-virtual-node in the cluster.
Procedure
Create a Knative Service, add the
alibabacloud.com/eci=true
label to the Service, and add thek8s.aliyun.com/eci-use-specs
annotation to specify the type of elastic container instance to be used. Then, run thekubectl apply
command to deploy the YAML file.Sample template:
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: helloworld-go namespace: vk spec: template: metadata: labels: alibabacloud.com/eci: "true" # Add the label. annotations: k8s.aliyun.com/eci-use-specs: "2-4Gi" # Specify the type of elastic container instance. spec: containers: - env: - name: TARGET value: "Knative" image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
After you complete the configuration, run the following command to verify that the configuration is successful:
kubectl -n vk get pod -o wide
Expected output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES helloworld-go-dqqhv-deployment-6d54c9c8dc-hkjwn 2/2 Running 0 40s 192.XX.0.80 virtual-node-eci-0 <none> <none>
The output indicates the two Elastic Container Instance-based pods are created.
References
When you use Knative, if you want to automatically scale out Elastic Container Instance-based pods to handle traffic spikes and use Elastic Compute Service (ECS)-based pods in the remaining time, see Use both ECS instances and elastic container instances in Knative.
You can use the image cache feature provided by Elastic Container Instance to accelerate image pulls and reduce instance creation time. For more information, see Use image caches to accelerate pod creation for Knative Services.