×
Community Blog Gray Verification of Traffic Based on Header in Knative

Gray Verification of Traffic Based on Header in Knative

This article describes the way to perform gray verification in Knative.

By Yuanyi

Introduction

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.

Tag Features in Knative

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.

1

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.

Set Tag-Based Header Policy in Knative

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.

  • This feature in Knative on Alibaba Cloud is enabled by default.
  • This feature in Knative for the community is disabled by default but can be enabled by running the following statements:
kubectl patch cm config-features -n knative-serving -p '{"data":{"tag-header-based-routing":"enabled"}}'

Gray Verification by Header

Prerequisites

After Knative is deployed on Alibaba Cloud, the Kourier gateway is used by default.

Configure a Service

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!

Upgrade Services

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.

Set New Version Tags

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!

Perform Gray Verification

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!

Summary

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!

0 0 0
Share on

Alibaba Container Service

173 posts | 31 followers

You may also like

Comments

Alibaba Container Service

173 posts | 31 followers

Related Products