concept environment variable in category knative

appears as: environment variables, environment variable, n environment variable
Knative in Action

This is an excerpt from Manning's book Knative in Action.

Configuration is your statement of what your running system should look like. You provide details about the desired container image, environment variables and the like. Knative converts this information into lower-level Kubernetes concepts like Deployments. In fact, those of you with some Kubernetes familiarity might be wondering what Knative is adding. After all, you can just create and submit a Deployment yourself, no need to use another component for that.

Everything from the kn CLI is present in the YAML version. We have a name, a container and an environment variable. We also have a fair amount more besides, including a fair amount of whitespace.

Listing 3.31. Using envFrom to stamp out environment variables
apiVersion: serving.knative.dev/v1
kind: Configuration
metadata:
  name: values-from-example
spec:
  template:
    spec:
      containers:
      - image: example.com/an/image
        envFrom:
        - configMapRef:
            name: example-configmap
        - secretRef:
            name: example-secret

This mechanism is relatively convenient, because it will take everything in the ConfigMaps and Secrets you provide and stamp out environment variables. If you have software that expects a bunch of variables set, then it’s easier to do it through ConfigMaps than to laboriously concatenate all of the settings into a very long kn command.