|
| 1 | +[id="serverless-customize-labels-annotations-routes_{context}"] |
| 2 | += Customizing labels and annotations for {product-title} routes |
| 3 | + |
| 4 | +{product-title} routes support the use of custom labels and annotations, which you can configure by modifying the `metadata` spec of a Knative service. Custom labels and annotations are propagated from the service to the Knative route, then to the Knative ingress, and finally to the {product-title} route. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | + |
| 8 | +* You must have the {ServerlessOperatorName} and Knative Serving installed on your {product-title} cluster. |
| 9 | + |
| 10 | +.Procedure |
| 11 | + |
| 12 | +. Create a Knative service that contains the label or annotation that you want to propagate to the {product-title} route: |
| 13 | +** To create a service by using YAML: |
| 14 | ++ |
| 15 | +.Example service created by using YAML |
| 16 | +[source,yaml] |
| 17 | +---- |
| 18 | +apiVersion: serving.knative.dev/v1 |
| 19 | +kind: Service |
| 20 | +metadata: |
| 21 | + name: <service_name> |
| 22 | + labels: |
| 23 | + <label_name>: <label_value> |
| 24 | + annotations: |
| 25 | + <annotation_name>: <annotation_value> |
| 26 | +... |
| 27 | +---- |
| 28 | +** To create a service by using the `kn` CLI, enter: |
| 29 | ++ |
| 30 | +.Example service created by using a `kn` command |
| 31 | +[source,terminal] |
| 32 | +---- |
| 33 | +$ kn service create <service_name> \ |
| 34 | + --image=<image> \ |
| 35 | + --annotation <annotation_name>=<annotation_value> \ |
| 36 | + --label <label_value>=<label_value> |
| 37 | +---- |
| 38 | + |
| 39 | +. Verify that the {product-title} route has been created with the annotation or label that you added by inspecting the output from the following command: |
| 40 | ++ |
| 41 | +.Example command for verification |
| 42 | +[source,terminal] |
| 43 | +---- |
| 44 | +$ oc get routes.route.openshift.io \ |
| 45 | + -l serving.knative.openshift.io/ingressName=<service_name> \ <1> |
| 46 | + -l serving.knative.openshift.io/ingressNamespace=<service_namespace> \ <2> |
| 47 | + -n knative-serving-ingress -o yaml \ |
| 48 | + | grep -e "<label_name>: \"<label_value>\"" -e "<annotation_name>: <annotation_value>" <3> |
| 49 | +---- |
| 50 | +<1> Use the name of your service. |
| 51 | +<2> Use the namespace where your service was created. |
| 52 | +<3> Use your values for the label and annotation names and values. |
0 commit comments