With each update to the configuration of a service, a new revision for the service is created. The service route points all traffic to the latest ready revision by default. You can change this behavior by defining which revisions gets a portion of the traffic.
Knative services allow for traffic mapping, which means that revisions of a service can be mapped to an allocated portion of traffic. Traffic mapping also provides an option to create unique URLs for particular revisions.
After you create a serverless application, the serverless application is displayed in the Topology view of the Developer perspective. The application revision is represented by the node and the serverless resource service is indicated by a quadrilateral around the node.
Any new change in the code or the service configuration triggers a revision, a snapshot of the code at a given time. For a service, you can manage the traffic between the revisions of the service by splitting and routing it to the different revisions as required.
To split traffic between multiple revisions of an application in the Topology view:
Click the serverless resource service, indicated by the quadrilateral, to see its overview in the side panel.
Click the Resources tab, to see a list of Revisions and Routes for the service.
Click the service, indicated by the S icon at the top of the side panel, to see an overview of the service details.
Click the YAML tab and modify the service configuration in the YAML editor, and click Save. For example, change the timeoutseconds
from 300 to 301 . This change in the configuration triggers a new revision. In the Topology view, the latest revision is displayed and the Resources tab for the service now displays the two revisions.
In the Resources tab, click the Set Traffic Distribution button to see the traffic distribution dialog box:
Add the split traffic percentage portion for the two revisions in the Splits field.
Add tags to create custom URLs for the two revisions.
Click Save to see two nodes representing the two revisions in the Topology view.
kn
provides commands that help you to control traffic mapping and how traffic is split between revisions.
You can use the kn service update
command with the --traffic
flag to update the traffic. This flag uses the following syntax:
--traffic RevisionName=Percent
where
* The --traffic
flag requires two values separated by separated by an equals sign (=
).
* The RevisionName
string refers to the name of the revision.
* Percent
integer denotes the traffic portion assigned to the revision.
The |
Update the percentage of traffic to be routed to a revision:
$ kn service update --traffic <@revision_name>=<percent_integer>
You can use the identifier |
A tag in a traffic block of service creates a custom URL, which points to a referenced revision. A user can define a unique tag for an available revision of a service which creates a custom URL by using the format http(s)://TAG-SERVICE.DOMAIN
.
A given tag must be unique to its traffic block of the service. kn
supports assigning and unassigning custom tags for revisions of services as part of the kn service update
command.
If you have assigned a tag to a particular revision, a user can reference the revision by its tag in the |
Use the following command:
$ kn service update svc --tag @latest=candidate --tag svc-vwxyz=current
|
Tags assigned to revisions in a traffic block can be unassigned. Unassigning tags removes the custom URLs.
If a revision is untagged and it is assigned 0% of the traffic, it is removed from the traffic block entirely. |
A user can unassign the tags for revisions using the kn service update
command:
$ kn service update svc --untag candidate
|
All traffic-related flags can be specified using a single kn service update
command.
kn
defines the precedence of these flags. The order of the flags specified when using the command is not taken into account.
The precedence of the flags as they are evaluated by kn
are:
--untag
: All the referenced revisions with this flag are removed from the traffic block.
--tag
: Revisions are tagged as specified in the traffic block.
--traffic
: The referenced revisions are assigned a portion of the traffic split.
kn
supports traffic operations on the traffic block of a service as part of the kn service update
command.
The following table displays a summary of traffic splitting flags, value formats, and the operation the flag performs. The Repetition column denotes whether repeating the particular value of flag is allowed in a kn service update
command.
Flag | Value(s) | Operation | Repetition |
---|---|---|---|
|
|
Gives |
Yes |
|
|
Gives |
Yes |
|
|
Gives |
No |
|
|
Gives |
Yes |
|
|
Gives |
No |
|
|
Removes |
Yes |