You can add Kubernetes annotations to a deployed Serverless function by adding them to the annotations section in the func.yaml configuration file.

There are two limitations of the function annotation feature:

  • Once a function annotation propagates to the corresponding Knative service on the cluster, it cannot be removed from the service by deleting it from the func.yaml file. You can remove the annotation from the Knative service by modifying the YAML file of the service directly, or by using the Developer Console.

  • You cannot set annotations that are set by Knative, for example, the autoscaling annotations.

Adding annotations to a function

Procedure
  1. Open the func.yaml file for your function.

  2. For every annotation that you want to add, add the following YAML to the annotations section:

    name: test
    namespace: ""
    runtime: go
    ...
    annotations:
      <annotation_name>: "<annotation_value>" (1)
    1 Substitute <annotation_name>: "<annotation_value>" with your annotation.

    For example, to indicate that a function was authored by Alice, you might include the following annotation:

    name: test
    namespace: ""
    runtime: go
    ...
    annotations:
      author: "alice@example.com"
  3. Save the configuration.

The next time you deploy your function to the cluster, the annotations are added to the corresponding Knative service.