Environmental Variables in Fission

434 views Asked by At

Is there a way to set environment variables in fission? I can't seem to find anything on their documentation and do not want to put credentials in the codebase.

I wasn't sure if it would make sense to add it as a build variable but don't know how that would work with the cli.

3

There are 3 answers

0
Andy Su On

You can do this By setting up a function yaml-spec

apiVersion: fission.io/v1
kind: Environment
metadata:
  creationTimestamp: null
  name: func-name
spec:
  builder:
    command: build
    container:
      name: ""
      resources: {}
    image: fission/python-builder
  imagepullsecret: myregistrykey
  keeparchive: false
  poolsize: 3
  resources: {}
  runtime:
    podspec:
      containers:
      - name: container-name
        env: # here !!!!!!!!!!!!
        - name: value1
          value: 1
        - name: value2
          value: 2
        resources: {}
    image: addr_of_image
  version: 2

please read: https://doc.crds.dev/github.com/fission/fission

0
Erwin On

As far as I know of the support for environment variables is being worked on. The relevant PR: https://github.com/fission/fission/pull/399

As a temporary workaround you could inject environment variables using a custom Fission environment. For example with the python environment:

FROM fission/python-env

ENV DB_CREDENTIALS=foobar

ENTRYPOINT ["python3"]
CMD ["server.py"]

Note that any function using the custom environment will have access to the environment variable(!)

0
viveksinghggits On

I think a good way to store the credentials would be storing them in the K8S cluster in ConfigMap resources and the accessing the in our code. You can follow this link to read more about how to access the configmap from fission code.