By Li Peng (Yuanyi)
Knative is an open-source Serverless application framework based on Kubernetes. It helps deploy and manage Serverless workloads and build enterprise-class Serverless platforms. Application Load Balancer (ALB) provides load balancing services that target the load scenarios at the application layer, such as HTTP, HTTPS, and Quick UDP Internet Connections (QUIC). ALB is highly elastic and can process a large amount of network traffic for seven layers. In addition, ALB supports gray releases for headers and cookies. This article describes how to integrate ALB in Alibaba Cloud Container Service Knative.
Currently, Container Service Knative supports community Kourier gateways and the integration with SLB gateways. However, these two gateways still have the following problems in use.
There are a few problems when using the native Kourier gateways provided by the Knative community:
Target: It provides cloud product ALB gateway capabilities in the Serverless Framework (Knative).
Benefits: It enhances the capabilities of Serverless Framework gateways and expands the scenarios applicable to ALB Ingress.
Basic Idea: Convert a Knative Ingress into a Kubernetes Ingress and then create an ALB and forwarding rule with the ALB Ingress Controller. The following figure shows the architecture:
A vSwitch should be specified to create an ALB instance. Therefore, users must configure the vSwitch ID in Knative.
Configure the parameters in the knative-serving namespace config-network configmap:
apiVersion: v1
kind: ConfigMap
metadata:
data:
ingress.class: alb.ingress.networking.knative.dev
vswitch-ids: vsw-2zeqgkyib34gw1fxxx,vsw-2zefv5qwao4prxxx
...
Header:
Knative currently supports the Header mode for gray release, which is implemented using Knative-Serving-Tag: {revision-tag}.
If you want to implement the integration of Knative and ALB, the key is the gray release based on cookies, headers, and weight ratios. Here, the implementation of gray release is mainly introduced.
Knative Ingress converts the weight of the revision service into the gray weight of the Kubernetes Ingress.
Example of Knative Service:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/maxScale: "100"
autoscaling.knative.dev/minScale: "0"
spec:
containers:
- env:
- name: TARGET
value: Knative11
image: registry-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
name: user-container
ports:
- containerPort: 8080
name: http1
protocol: TCP
traffic:
- latestRevision: false
percent: 50
revisionName: helloworld-go-00002
- latestRevision: false
percent: 50
revisionName: helloworld-go-00001
Internal conversion to Kubernetes Ingress is listed below:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/actions.forward-default: '{"type":"ForwardGroup","forwardConfig":{"targetGroups":[{"serviceName":"helloworld-go-00002","servicePort":80,"weight":50},{"serviceName":"helloworld-go-00001","servicePort":80,"weight":50}]}}'
labels:
knative.aliyun.com/ingress: helloworld-go
name: helloworld-go
namespace: default
spec:
ingressClassName: knative-alb-ingress-internet
rules:
- host: helloworld-go.default.example.com
http:
paths:
- backend:
service:
name: forward-default
port:
name: use-annotation
path: /
pathType: Prefix
- host: helloworld-go.default.svc.cluster.local
http:
paths:
- backend:
service:
name: forward-default
port:
name: use-annotation
path: /
pathType: Prefix
Service access:
$ curl ${INGRESS_DNS} -H "Host:helloworld-go.default.example.com"
Hello Knative!
Hello Knative 2!
Currently, the gray release of Header is implemented by configuring tag-header-based-routing with Knative Service.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/maxScale: "100"
autoscaling.knative.dev/minScale: "0"
spec:
containers:
- env:
- name: TARGET
value: Knative11
image: registry-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
name: user-container
ports:
- containerPort: 8080
name: http1
protocol: TCP
traffic:
- latestRevision: false
percent: 0
revisionName: helloworld-go-00002
tag: rev1
- latestRevision: false
percent: 100
revisionName: helloworld-go-00001
Internal conversion to Kubernetes Ingress is listed below:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/actions.forward-default: '{"type":"forward","forwardConfig":{"serverGroups":[{"serviceName":"helloworld-go-00002","servicePort":80,"weight":50},{"serviceName":"helloworld-go-00001","servicePort":80,"weight":50}]}}'
alb.ingress.kubernetes.io/actions.forward-tag: '{"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"helloworld-go-00002","servicePort":80,"weight":100}]}}'
alb.ingress.kubernetes.io/conditions.forward-tag: '[{"Type":"Header","CookieConfig":{"Values":null},"HeaderConfig":{"Key":"Knative-Serving-Tag","Values":["rev1"]}}]'
labels:
knative.aliyun.com/ingress: helloworld-go
name: helloworld-go
namespace: default
spec:
ingressClassName: knative-alb-ingress-internet
rules:
- host: helloworld-go.default.a97e861255a18699.app.alicontainer.com
http:
paths:
- backend:
service:
name: forward-default
port:
name: use-annotation
path: /
pathType: Prefix
- host: helloworld-go.default.svc.cluster.local
http:
paths:
- backend:
service:
name: forward-default
port:
name: use-annotation
path: /
pathType: Prefix
- host: helloworld-go.default.a97e861255a18699.app.alicontainer.com
http:
paths:
- backend:
service:
name: forward-tag
port:
name: use-annotation
path: /
pathType: Prefix
- host: helloworld-go.default.svc.cluster.local
http:
paths:
- backend:
service:
name: forward-tag
port:
name: use-annotation
path: /
pathType: Prefix
- host: rev1-helloworld-go.default.svc.cluster.local
http:
paths:
- backend:
service:
name: forward-tag
port:
name: use-annotation
path: /
pathType: Prefix
Access Method:
curl ${INGRESS_DNS} -H "Host:helloworld-go.default.example.com" -H "Knative-Serving-Tag:rev1"
In Knative Service, the traffic revision corresponding to the Header can be specified using annotations.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
annotations:
alicloud.serving.knative.dev/headers: [{revision:helloworld-go-00002,headers:{demo:test}}]
name: helloworld-go
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/maxScale: "100"
autoscaling.knative.dev/minScale: "0"
spec:
containers:
- env:
- name: TARGET
value: Knative11
image: registry-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
name: user-container
ports:
- containerPort: 8080
name: http1
protocol: TCP
traffic:
- latestRevision: false
percent: 0
revisionName: helloworld-go-00002
- latestRevision: false
percent: 100
revisionName: helloworld-go-00001
Access Method:
curl ${INGRESS_IP} -H "Host:helloworld-go.default.example.com" --header "demo=always" --header "header2=v2"
In Knative Service, the traffic revision corresponding to the Cookie can be specified using annotations.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
annotations:
alicloud.serving.knative.dev/cookies: [{revision:helloworld-go-00002,cookies:{demo:always,cookie2:v2}}]
name: helloworld-go
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/maxScale: "100"
autoscaling.knative.dev/minScale: "0"
spec:
containers:
- env:
- name: TARGET
value: Knative11
image: registry-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
name: user-container
ports:
- containerPort: 8080
name: http1
protocol: TCP
traffic:
- latestRevision: false
percent: 0
revisionName: helloworld-go-00002
- latestRevision: false
percent: 100
revisionName: helloworld-go-00001
Access Method:
curl ${INGRESS_DNS} -H "Host:helloworld-go.default.example.com" --cookie "demo=always" --cookie "cookie2=v2"
Integrating Knative with ALB can enhance the productization capabilities of Knative Serverless and expand the scenarios applicable to ALB Ingress.
Learn more about the product:
https://www.alibabacloud.com/help/en/container-service-for-kubernetes/latest/alb
The Definition of the New Service Mesh-Driven Scenario: AI Model Services - Model Mesh
Comprehensive Analysis of Kubernetes Log Collection Principles
160 posts | 29 followers
FollowAlibaba Cloud Native Community - April 9, 2024
Alibaba Container Service - August 1, 2023
Alibaba Cloud Native - September 11, 2023
Alibaba Cloud Community - July 11, 2024
Alibaba Container Service - August 25, 2020
Alibaba Cloud Native Community - September 20, 2023
160 posts | 29 followers
FollowProvides a control plane to allow users to manage Kubernetes clusters that run based on different infrastructure resources
Learn MoreAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreVisualization, O&M-free orchestration, and Coordination of Stateful Application Scenarios
Learn MoreMore Posts by Alibaba Container Service