By Yuanyi
The canary release can be performed based on traffic percentage in Knative. However, sometimes gray verification in specified versions is required for requests. The common practice is to set parameters in the request header. Then, the system verifies in the specified version based on the header. In addition to traffic-based gray verification, does Knative support header-based gray verification in specified versions? The answer is yes. Header-based gray verification can be implemented with the Kourier gateway in Knative V0.18.0.
After configuring a Knative Service in Knative, the access domain name of the Service (for example, helloworld.default.example.com), will be generated by default. Through this domain name, different versions can be accessed according to the traffic percentage of each revision. Moreover, Knative supports features of specifying a certain version the users want to access, which sets a tag for the version.
The tagged revision will generate a domain name, such as test-helloworld.default.example.com, so that the specific version can be accessed directly when users access the domain name.
Generally, tags are used to test the functionality of a version that has not been introduced online. However, this feature cannot be used for the gray verification of the specified version because the domain name for online service access is fixed. Therefore, the Knative community provides a policy of setting header routing based on tag settings.
In Knative V0.18.0, users can add Knative-Serving-Tag: {revision-tag}
to the request header to specify that the request goes to the corresponding version of the tag.
Currently, this feature is supported by Istio, Contour, and Kourier.
kubectl patch cm config-features -n knative-serving -p '{"data":{"tag-header-based-routing":"enabled"}}'
After Knative is deployed on Alibaba Cloud, the Kourier gateway is used by default.
First, configure a helloworld-go
service. Note: Tag features need to be enabled. Set route.serving.knative.aliyun.com/revision-tag: "on"
in the service comment.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
annotations:
route.serving.knative.aliyun.com/revision-tag: "on"
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
Run the following deployment command:
kubectl apply -f helloworld.yaml
View the version information:
kubectl get revision
NAME CONFIG NAME K8S SERVICE NAME GENERATION READY REASON
helloworld-go-k77jq helloworld-go helloworld-go-k77jq 1 True
Access the service:
richard@B-N3TEMD6P-1650 tag-route % curl -H "host: helloworld-go.default.example.com" http://39.106.114.214
Hello World!
Here, print different outputs by modifying the environment variable TARGET. Meanwhile, set the traffic of the new version to 0 so the request is routed to the original version.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
annotations:
route.serving.knative.aliyun.com/revision-tag: "on"
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
env:
- name: TARGET
value: "Knative"
traffic:
- latestRevision: true
percent: 0
- latestRevision: false
percent: 100
revisionName: helloworld-go-k77jq
Run the following deployment command:
kubectl apply -f helloworld.yaml
Check that the new version has been created:
kubectl get revision
NAME CONFIG NAME K8S SERVICE NAME GENERATION READY REASON
helloworld-go-k77jq helloworld-go helloworld-go-k77jq 1 True
helloworld-go-zgklc helloworld-go helloworld-go-zgklc 2 True
Access the service:
curl -H "host: helloworld-go.default.example.com" http://39.106.114.214
Hello World!
The output information is from the original version, as expected.
Run the following command to modify the service:
kubectl edit ksvc helloworld-go
Set the tag as tag: demo
on new version:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
annotations:
route.serving.knative.aliyun.com/revision-tag: "on"
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
env:
- name: TARGET
value: "Knative"
traffic:
- latestRevision: false
percent: 0
revisionName: helloworld-go-zgklc
tag: demo
- latestRevision: false
percent: 100
revisionName: helloworld-go-k77jq
Access the specified version (helloworld-go-zgklc)
:
curl -H "host: demo-helloworld-go.default.example.com" http://39.106.114.214
Hello Knative!
The way to perform gray verification based on the header is simple. Add Knative-Serving-Tag
when accessing the domain name helloworld-go.default.example.com
:
curl -H "host: helloworld-go.default.example.com" -H "Knative-Serving-Tag:demo" http://39.106.114.214
Hello Knative!
This article describes the way to perform gray verification after setting Knative-Serving-Tag
in the header in Knative. You are welcome to try it out today!
173 posts | 31 followers
FollowAlibaba Container Service - September 14, 2022
Alibaba Cloud Native Community - February 22, 2023
Alibaba Cloud Native Community - November 15, 2023
Alibaba Cloud Native Community - May 17, 2022
Alibaba Cloud Native Community - March 11, 2024
Alibaba Container Service - July 22, 2021
173 posts | 31 followers
FollowProvides a control plane to allow users to manage Kubernetes clusters that run based on different infrastructure resources
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 MoreServerless Application Engine (SAE) is the world's first application-oriented serverless PaaS, providing a cost-effective and highly efficient one-stop application hosting solution.
Learn MoreMore Posts by Alibaba Container Service