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.

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 -n fission-function 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 -n fission-function 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 -n fission-function exec -it <pod> -c fetcher sh
/ # env
TEST_KEY=TESTVALUE
Last modified December 7, 2019: Add spec documentation (#174) (1e23fa5)