Knative: Operator’s Handbook

Naming Revisions deterministically

As seen in Splitting traffic, with “randomly generated” Revision names by default, you need to copy-paste them into your Service's spec.traffic field to effectively split traffic while releasing a new version.

However, Knative allows you to:

  1. specify a new Revision's name ahead of time,
  2. and use this Revision name to split traffic while releasing the new Revision.

You can use spec.template.metadata.name to decide the name of a Revision.

For example, deploy :1.0 image with revision name hello-001:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: hello
spec:
  template:
    metadata:
      name: hello-001
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:1.0

Then, deploy a new Revision with the :2.0 image, by updating Service and setting the new Revision name to hello-002, and splitting traffic in one operation:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: hello
spec:
  template:
    metadata:
      name: hello-002
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:2.0
  traffic:
  - revisionName: hello-001
    percent: 50
  - revisionName: hello-002
    percent: 50

You can see that applying this new Service manifest created two Revisions and successfully split the traffic between the two.

Show output
$ kubectl get revision
NAME                   SERVICE NAME           GENERATION   READY   REASON
hello-001              hello-001              1            True
hello-002              hello-002              2            True

$ kubectl describe ksvc hello
[...]
  Traffic:
    Percent:          50
    Revision Name:    hello-001
    Percent:          50
    Revision Name:    hello-002

Using this trick, you can automate splitting traffic between your new Revisions.