Environment variables

You can use environment variables to configure an existing runtime, to read existing configuration or to build your own runtime based on them.

Environments passed to runtimes

Every runtime provides its own unique environment configuration which can be read by a server and the handler.js file during the container run:

Common environments

EnvironmentDefaultDescription
FUNC_HANDLERmainThe name of the exported Function inside the MOD_NAME file.
MOD_NAMEhandlerThe name of the main exported file. The extension must be added on the server side and must be equal to .py for the Python runtimes and .js for the Node.js ones.
FUNC_PORT8080The right port, a server listens to.
SERVICE_NAMESPACEThe Namespace where the right Function exists on a cluster.
KUBELESS_INSTALL_VOLUME/kubelessFull path to volume mount with users source code.
FUNC_RUNTIMEThe name of the actual runtime. Possible values: python39, nodejs14, nodejs16.
TRACE_COLLECTOR_ENDPOINThttp://tracing-jaeger-collector.kyma-system.svc.cluster.local:4318/v1/tracesFull address of the Open-Telemetry Trace Collector.
JAEGER_SERVICE_ENDPOINThttp://tracing-jaeger-collector.kyma-system.svc.cluster.local:14268/api/tracesDeprecated in 2.8 Full address of the Jaeger service.
PUBLISHER_PROXY_ADDRESShttp://eventing-publisher-proxy.kyma-system.svc.cluster.local/publishFull address of the Publisher Proxy service.

NOTE: TRACE_COLLECTOR_ENDPOINT replaced JAEGER_SERVICE_ENDPOINT in Kyma 2.8. Functions built (or re-built) after 2.8 use OpenTelemetry protocol-compliant endpoint, as defined by TRACE_COLLECTOR_ENDPOINT. JAEGER_SERVICE_ENDPOINT will be removed in Kyma 2.10.

Specific environments

There are a few environments that occur only for a specific runtimes. The following list includes all of them:

Node.js runtimes-specific environments

EnvironmentDefaultDescription
NODE_PATH$(KUBELESS_INSTALL_VOLUME)/node_modulesFull path to fetched users dependencies.

Python runtime-specific environment variables

EnvironmentDefaultDescription
PYTHONPATH$(KUBELESS_INSTALL_VOLUME)/lib.python3.9/site-packages:$(KUBELESS_INSTALL_VOLUME)List of directories that Python must add to the sys.path directory list.
PYTHONUNBUFFEREDTRUEDefines if Python's logs must be buffered before printing them out.

Configure runtime

You can configure environment variables either separately for a given runtime or make them runtime-agnostic using a ConfigMap.

Define environment variables in a Config Map

ConfigMaps allow you to define Function's environment variables for any runtime through key-value pairs. After you define the values in a ConfigMap, simply reference it in the Function custom resource (CR) through the valueFrom parameter. See an example of such a Function CR that specifies the my-var value as a reference to the key stored in the my-vars-cm ConfigMap as the MY_VAR environment variable.

Click to copy
apiVersion: serverless.kyma-project.io/v1alpha1
kind: Function
metadata:
name: sample-cm-env-values
namespace: default
spec:
env:
- name: MY_VAR
valueFrom:
configMapKeyRef:
name: my-vars-cm
key: my-var
source: |
module.exports = {
main: function (event, context) {
return process.env["MY_VAR"];
}
}

Node.js runtime-specific environment variables

To configure the Function with the Node.js runtime, override the default values of these environment variables:

Environment variableDescriptionTypeDefault value
FUNC_TIMEOUTSpecifies the number of seconds in which a runtime must execute the code.Number180
REQ_MB_LIMITSpecifies the payload body size limit in megabytes.Number1
KYMA_INTERNAL_LOGGER_ENABLEDEnables the default HTTP request logger which uses the standard Apache combined log output. To enable it, set its value to true.Booleanfalse

See kubeless.js to get a deeper understanding of how the Express server, that acts as a runtime, uses these values internally to run Node.js Functions.

See the example of a Function with these environment variables set:

Click to copy
apiVersion: serverless.kyma-project.io/v1alpha1
kind: Function
metadata:
name: sample-fn-with-envs
namespace: default
spec:
env:
- name: FUNC_TIMEOUT
value: "2"
- name: REQ_MB_LIMIT
value: "10"
source: |
module.exports = {
main: function (event, context) {
return "Hello World!";
}
}

Python runtime-specific environment variables

To configure a Function with the Python runtime, override the default values of these environment variables:

Environment variableDescriptionUnitDefault value
FUNC_MEMFILE_MAXSpecifies the maximum size of the memory buffer for the HTTP request body in bytes.Number100*1024*1024
CHERRYPY_NUMTHREADSSpecifies the number of requests that can be handled in parallelNumber50
KYMA_INTERNAL_LOGGER_ENABLEDEnables the default HTTP request logger which uses the standard Apache combined log output. To enable it, set its value to true.Booleanfalse

See kubeless.py to get a deeper understanding of how the Bottle server, that acts as a runtime, uses these values internally to run Python Functions.

Click to copy
apiVersion: serverless.kyma-project.io/v1alpha1
kind: Function
metadata:
name: sample-fn-with-envs
namespace: default
spec:
env:
- name: FUNC_MEMFILE_MAX
value: "1048576" # 1MiB
source: |
def main(event. context):
return "Hello World!"