Environment Variable

Functions sometimes require to pass-in parameter through environment variable to control internal behavior of a function like GOMAXPROCS for Go or you may want to expose secret/configmap as environment variable. In such cases, we can add env to PodSpec.

As Docker doesn’t support to change configuration of a container once it’s created. To ensure different executor types have consistent behavior, Fission only supports to set environment variable at Environment-level now.

Add environment variable

Let’s try to add environment variable setting to fetcher container:

apiVersion: fission.io/v1 kind: Environment ... spec: runtime: podspec: containers: - name: fetcher env: - name: LOG_LEVEL value: info

Now, you shall see the environment variable in container:

$ kubectl exec -it <pod> -c fetcher sh / # env LOG_LEVEL=info

Expose Secret/ConfigMap as environment variable

Let’s create a ConfigMap called my-configmap.

$ kubectl create configmap my-configmap --from-literal=TEST_KEY="TESTVALUE"

And add PodSpec with configMapKeyRef to environment spec file.

apiVersion: fission.io/v1 kind: Environment ... spec: runtime: podspec: containers: - name: fetcher env: - name: TEST_KEY valueFrom: configMapKeyRef: name: my-configmap key: TEST_KEY
$ kubectl exec -it <pod> -c fetcher sh / # env TEST_KEY=TESTVALUE