Knative: Operator’s Handbook

Splitting traffic

Using Revision objects, you can split a Knative Service's traffic. This is because each Revision creates a Knative Service, which is a routable address on the load balancer.

For example, if you have two Revisions of a Service (see Revisions) you can update spec.traffic field of Service to split the traffic 50%-50%:

$ kubectl revision # make a note of revision NAMEs
$ kubectl edit ksvc hello

Normally, Knative Service will send 100% of the traffic to the last deployed revision that is “ready”. You can see this in Service’s spec.traffic field:

[...]
spec:
  traffic:
  - latestRevision: true
    percent: 100
    revisionName: hello-kjzfl

If you want to split the traffic between multiple Revisions of this Knative Service, add a new target (with the old Revision’s name) here and split traffic (make sure you're not updating status.traffic field, as it won't do anything):

[...]
spec:
  traffic:
  - percent: 50
    revisionName: hello-kjzfl
  - percent: 50
    revisionName: hello-js4x4

After saving the kubectl edit session, visit the app to see traffic split in action.

Note: Consider removing latestRevision: true field. It is an alternative to the revisionName and usually does more harm than good.

Show output
while do; ( curl -sH "Host: hello.default.example.com" IP_ADDRESS | grep Version ) ; done

Version: 1.0.0
Version: 1.0.0
Version: 2.0.0
Version: 1.0.0
Version: 2.0.0
Version: 2.0.0
Version: 2.0.0
Version: 2.0.0
Version: 1.0.0
Version: 2.0.0
Version: 2.0.0
Version: 1.0.0
...

As you might be able to tell, it's cumbersome to copy paste Revision names and edit the Service object manually to split the traffic. But you can actually control Revision names.