Tag Header Based Routing
Tag header based routing allows users to send requests directly to specific tagged revisions with the same URL of Knative Service. To do this, you must set the specific header in the request.
Currently Istio, Contour and Kourier ingress support this feature.
Prerequestie
Move into the docs directory:
This feature is disabled by default. To enable this feature, run the following command:
kubectl patch cm config-network -n knative-serving -p '{"data":{"tagHeaderBasedRouting":"Enabled"}}'
Build images
Follow the instructions in helloworld-go to build the helloworld
image and upload it to your container repository.
In this sample, two Revisions are created. The first Revision is tagged with rev1
. With this configuration, users can send requests directly to the first Revision using the URL of Knative Service plus the header Knative-Serving-Tag: rev1
.
The Knative Service is configured to route all of the traffic to the second Revision, which means if users do not provide the Knative-Serving-Tag
or they provide an incorrect value for Knative-Serving-Tag
, the requests will be routed to the second Revision.
Run the following command to set up the Knative Service and Revisions.
Check the created resources
Check the two created Revisions using the following command
kubectl get revisions
You should see there are two Revisions: tag-header-revision-1
and tag-header-revision-2
. It may take a few minutes for the Revisions to become ready.
Check the Knative Service using the following command
- revisionName: tag-header-revision-1
percent: 0
tag: rev1
percent: 100
Run the following command to send a request to the first Revision.
curl ${INGRESS_IP} -H "Host:tag-header.default.example.com" -H "Knative-Serving-Tag:rev1"
where
${INGRESS_IP}
is the IP of your ingress.You should get the following response:
Hello First Revision!
Run the following command to send requests without the
Knative-Serving-Tag
header:You should get the response from the second Revision:
Hello Second Revision!
Run the following command to send requests with an incorrect
Knative-Serving-Tag
header:Hello Second Revision!