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

    1. Move into the docs directory:

    This feature is disabled by default. To enable this feature, run the following command:

    1. 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

    1. 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

    1. - revisionName: tag-header-revision-1
    2. percent: 0
    3. tag: rev1
    4. percent: 100
    1. Run the following command to send a request to the first Revision.

      1. 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:

      1. Hello First Revision!
    2. Run the following command to send requests without the Knative-Serving-Tag header:

      You should get the response from the second Revision:

      1. Hello Second Revision!
    3. Run the following command to send requests with an incorrect Knative-Serving-Tag header:

        1. Hello Second Revision!