|
| 1 | +[id="serverless-functions-func-yaml_{context}"] |
| 2 | += Configurable fields in func.yaml |
| 3 | + |
| 4 | +Many of the fields in `func.yaml` are generated automatically when you create, build, and deploy your function. However, there are also fields that you modify manually to change things, such as the function name or the image name. |
| 5 | + |
| 6 | +== builder |
| 7 | + |
| 8 | +The `builder` field specifies the Buildpack builder image to use when building the function. In most cases, this value should not be changed. When you do change it, use a value that is listed in the `builderMap` field. |
| 9 | + |
| 10 | +== builderMap |
| 11 | + |
| 12 | +Some function runtimes can be built in multiple ways. For example, a Quarkus function can be built for the JVM or as a native binary. The `builderMap` field contains all of the builders available for a given runtime. |
| 13 | + |
| 14 | +== envs |
| 15 | + |
| 16 | +The `envs` field enables you to set environment variables to be available to your function at runtime. You can set an environment variable in several different ways: |
| 17 | + |
| 18 | +. Directly from a value. |
| 19 | +. From a value assigned to a local environment variable. See the section "Referencing local environment variables from func.yaml fields" for more information. |
| 20 | +. From a key-value pair stored in a secret or config map. |
| 21 | +. You can also import all key-value pairs stored in a secret or config map, with keys used as names of the created environment variables. |
| 22 | + |
| 23 | +This examples demonstrates the different ways to set an environment variable: |
| 24 | + |
| 25 | +[source,yaml] |
| 26 | +---- |
| 27 | +name: test |
| 28 | +namespace: "" |
| 29 | +runtime: go |
| 30 | +... |
| 31 | +envs: |
| 32 | +- name: EXAMPLE1 <1> |
| 33 | + value: value |
| 34 | +- name: EXAMPLE2 <2> |
| 35 | + value: '{{ env:LOCAL_ENV_VALUE }}' |
| 36 | +- name: EXAMPLE3 <3> |
| 37 | + value: '{{ secret:mysecret:key }}' |
| 38 | +- name: EXAMPLE4 <4> |
| 39 | + value: '{{ configMap:myconfigmap:key }}' |
| 40 | +- value: '{{ secret:mysecret2 }}' <5> |
| 41 | +- value: '{{ configMap:myconfigmap2 }}' <6> |
| 42 | +---- |
| 43 | +<1> An environment variable set directly from a value. |
| 44 | +<2> An environment variable set from a value assigned to a local environment variable. |
| 45 | +<3> An environment variable assigned from a key-value pair stored in a secret. |
| 46 | +<4> An environment variable assigned from a key-value pair stored in a config map. |
| 47 | +<5> A set of environment variables imported from key-value pairs of a secret. |
| 48 | +<6> A set of environment variables imported from key-value pairs of a config map. |
| 49 | + |
| 50 | +== volumes |
| 51 | + |
| 52 | +The `volumes` field enables you to mount secrets and config maps as a volume accessible to the function at the specified path, as shown in the following example: |
| 53 | + |
| 54 | +[source,yaml] |
| 55 | +---- |
| 56 | +name: test |
| 57 | +namespace: "" |
| 58 | +runtime: go |
| 59 | +... |
| 60 | +volumes: |
| 61 | +- secret: mysecret <1> |
| 62 | + path: /workspace/secret |
| 63 | +- configMap: myconfigmap <2> |
| 64 | + path: /workspace/configmap |
| 65 | +---- |
| 66 | +<1> The `mysecret` secret is mounted as a volume residing at `/workspace/secret`. |
| 67 | +<2> The `myconfigmap` config map is mounted as a volume residing at `/workspace/configmap`. |
| 68 | + |
| 69 | +== options |
| 70 | + |
| 71 | +The `options` field enables you to modify Knative Service properties for the deployed function, such as autoscaling. If these options are not set, the default ones are used. |
| 72 | + |
| 73 | +These options are available: |
| 74 | + |
| 75 | +* `scale` |
| 76 | +** `min`: The minimum number of replicas. Must be a non-negative integer. The default is 0. |
| 77 | +** `max`: The maximum number of replicas. Must be a non-negative integer. The default is 0, which means no limit. |
| 78 | +** `metric`: Defines which metric type is watched by the Autoscaler. It can be set to `concurrency`, which is the default, or `rps`. |
| 79 | +** `target`: Recommendation for when to scale up based on the number of concurrently incoming requests. The `target` option can be a float value greater than 0.01. The default is 100, unless the `options.resources.limits.concurrency` is set, in which case `target` defaults to its value. |
| 80 | +** `utilization`: Percentage of concurrent requests utilization allowed before scaling up. It can be a float value between 1 and 100. The default is 70. |
| 81 | +* `resources` |
| 82 | +** `requests` |
| 83 | +*** `cpu`: A CPU resource request for the container with deployed function. |
| 84 | +*** `memory`: A memory resource request for the container with deployed function. |
| 85 | +** `limits` |
| 86 | +*** `cpu`: A CPU resource limit for the container with deployed function. |
| 87 | +*** `memory`: A memory resource limit for the container with deployed function. |
| 88 | +*** `concurrency`: Hard Limit of concurrent requests to be processed by a single replica. It can be integer value greater than or equal to 0, default is 0 - meaning no limit. |
| 89 | + |
| 90 | +This is an example configuration of the `scale` options: |
| 91 | + |
| 92 | +[source,yaml] |
| 93 | +---- |
| 94 | +name: test |
| 95 | +namespace: "" |
| 96 | +runtime: go |
| 97 | +... |
| 98 | +options: |
| 99 | + scale: |
| 100 | + min: 0 |
| 101 | + max: 10 |
| 102 | + metric: concurrency |
| 103 | + target: 75 |
| 104 | + utilization: 75 |
| 105 | + resources: |
| 106 | + requests: |
| 107 | + cpu: 100m |
| 108 | + memory: 128Mi |
| 109 | + limits: |
| 110 | + cpu: 1000m |
| 111 | + memory: 256Mi |
| 112 | + concurrency: 100 |
| 113 | +---- |
| 114 | + |
| 115 | +== image |
| 116 | + |
| 117 | +The `image` field sets the image name for your function after it has been built. You can modify this field. If you do, the next time you run `kn func build` or `kn func deploy`, the function image will be created with the new name. |
| 118 | + |
| 119 | +== imageDigest |
| 120 | + |
| 121 | +The `imageDigest` field contains the SHA256 hash of the image manifest when the function is deployed. Do not modify this value. |
| 122 | + |
| 123 | +== name |
| 124 | + |
| 125 | +The `name` field defines the name of your function. This value is used as the name of your Knative service when it is deployed. You can change this field to rename the function on subsequent deployments. |
| 126 | + |
| 127 | +== namespace |
| 128 | + |
| 129 | +The `namespace` field specifies the namespace in which your function is deployed. |
| 130 | + |
| 131 | +== runtime |
| 132 | + |
| 133 | +The `runtime` field specifies the language runtime for your function, for example, `python`. |
| 134 | + |
| 135 | +== template |
| 136 | + |
| 137 | +The `template` field specifies the type of the invocation event that triggers your function. You can set it to `http` for triggering with plain HTTP requests or to `events` for triggering with CloudEvents. |
0 commit comments