Knative on Alibaba Cloud: The Ultimate Serverless Experience

Development History of Cloud Hosts

  • Port conflicts
  • Resource isolation
  • System dependency and high O&M difficulty

Knative Serving

  • You must manage your Ingress Controller.
  • You must maintain the relationship between the ingress and services when exposing services externally.
  • If you need to implement canary release, you must perform rolling updates by using multiple deployments.
  • You only need to maintain one type of resource, the Knative Service.

Application Hosting

Traffic Management

Canary Release

Scaling

Why Did We Develop Serverless Kubernetes?

Highlights

SLB-based Gateways

Cost-effective Reserved Instances

  • Request processing timeout period: If a request is not processed within this time period, the system considers the request to have failed.
  • Burst concurrency: A maximum number of concurrent functions is specified for each function by default. If the requested number of functions exceeds this upper limit, the system enables throttling.
  • CPU and memory: The maximum CPU utilization and maximum memory usage cannot be exceeded.

Demos

# kubectl -n knative-serving get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-gateway LoadBalancer 172.19.8.35 47.102.220.35 80:30695/TCP 26h

Deploy the Coffee Service

# cat coffee.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: coffee
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/target: "10"
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8
env:
- name: TARGET
value: "coffee"
# kubectl get ksvc
NAME URL LATESTCREATED LATESTREADY READY REASON
coffee http://coffee.default.example.com coffee-fh85b coffee-fh85b True
# curl -H "Host: coffee.default.example.com" http://47.102.220.35
Hello coffee!

Auto Scaling

# kubectl get pod
NAME READY STATUS RESTARTS AGE
coffee-bwl9z-deployment-765d98766b-nvwmw 2/2 Running 0 42s
# cat coffee-v2.yaml
... ...
name: coffee-v2
annotations:
autoscaling.knative.dev/target: "10"
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8
... ...
hey -z 30s -c 90 --host "coffee.default.example.com" "http://47.100.6.39/?sleep=100"
  • -z 30s specifies that the stress test lasts for 30 seconds.
  • -c 90 specifies that 90 concurrent requests are initiated in the stress test.
  • --host "coffee.default.example.com" specifies the host to bind.
  • "http://47.100.6.39/?sleep=100" specifies the request URL. In particular, sleep=100 indicates that the image test sleeps for 100 milliseconds, just like a real online service.

Reserved Instances

# kubectl get pod
NAME READY STATUS RESTARTS AGE
coffee-bwl9z-deployment-reserve-85fd89b567-vpwqc 2/2 Running 0 5m24s
# cat coffee-set-reserve.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: coffee
spec:
template:
metadata:
annotations:
knative.aliyun.com/reserve-instance-eci-use-specs: "ecs.t5-c1m2.large"
autoscaling.knative.dev/target: "10"
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8
env:
- name: TARGET
value: "coffee-set-reserve"
# kubectl get pod
NAME READY STATUS RESTARTS AGE
coffee-vvfd8-deployment-reserve-845f79b494-lkmh9 2/2 Running 0 2m37s
# kubectl get pod coffee-vvfd8-deployment-reserve-845f79b494-lkmh9 -oyaml |head -20
apiVersion: v1
kind: Pod
metadata:
annotations:
... ...
k8s.aliyun.com/eci-instance-cpu: "2.000"
k8s.aliyun.com/eci-instance-mem: "4.00"
k8s.aliyun.com/eci-instance-spec: ecs.t5-c1m2.large
... ...

Upgrade the Coffee Service

# kubectl get pod
NAME READY STATUS RESTARTS AGE
coffee-fh85b-deployment-8589564f7b-4lsnf 1/2 Running 0 26s
# cat coffee-v1.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: coffee
spec:
template:
metadata:
name: coffee-v1
annotations:
autoscaling.knative.dev/target: "10"
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8
env:
- name: TARGET
value: "coffee-v1"
  • The current deployment revision is named coffee-v1. If no name is specified, the system automatically generates a name for the revision.
  • The environment variable contains "v1". Therefore, according to the HTTP return code, you can determine that version v1 is providing the current service.
# curl -H "Host: coffee.default.example.com" http://47.102.220.35
Hello coffee-v1!
# kubectl get pod
NAME READY STATUS RESTARTS AGE
coffee-v1-deployment-5c5b59b484-z48gm 2/2 Running 0 54s

Summary

References

Original Source:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

4.97K Followers

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com