# Injecting environment variables from ConfigMap

Use Kubernetes ConfigMap to provide non-sensitive configuration (such as API endpoints, feature flags, or application settings) as environment variables to your data integration tasks (including big data), Data Services, and Routes tasks.

## Before you begin

See [Prerequisites and Important considerations](https://help.qlik.com/talend/en-US/dynamic-engine-configuration-guide/Cloud/custom-kubernetes-resource-mounting).

## Procedure

1. Prepare a ConfigMap resource file with environment variables.
   ### Example

   For example, create a file named configmap-external-config.yaml:
   ```
   cat <<EOF > configmap-external-config.yaml
   apiVersion: v1
   kind: ConfigMap
   metadata:
     name: external-config
     namespace: qlik-processing-env-$DYNAMIC_ENGINE_ENVIRONMENT_ID
   data:
     API_ENDPOINT: "https://api.example.com/v1"
     FEATURE_FLAG_ENABLED: "true"
     LOG_LEVEL: "INFO"
     MAX_RETRIES: "3"
   EOF
   ```

   Replace $DYNAMIC\_ENGINE\_ENVIRONMENT\_ID with your environment ID and update the configuration values with your actual data.
2. Create a Helm values file that references the ConfigMap.
   ### Example

   Create a file named configmap-values.yaml. The content varies depending on which task types will consume this ConfigMap.
   * For Data Integration tasks:
     ```
     configuration:
       jobDeployment:
         additionalSpec:
           enabled: true
           envFrom:
             - configMapRef:
                 name: external-config
     ```
   * For Data Service and Route tasks:
     ```
     configuration:
       dataServiceRouteDeployment:
         additionalSpec:
           enabled: true
           envFrom:
             - configMapRef:
                 name: external-config
     ```
   * To combine both:
     ```
     configuration:
       jobDeployment:
         additionalSpec:
           enabled: true
           envFrom:
             - configMapRef:
                 name: external-config

       dataServiceRouteDeployment:
         additionalSpec:
           enabled: true
           envFrom:
             - configMapRef:
                 name: external-config
     ```

   Information noteTip: The additionalSpec.envFrom.configMapRef structure loads all keys from the ConfigMap as environment variables. All keys become available with their exact names specified in the ConfigMap, such as API\_ENDPOINT or FEATURE\_FLAG\_ENABLED.
3. Deploy or upgrade your Dynamic Engine environment to create the required namespace, if this has not been done previously.
   ```
   helm upgrade --install dynamic-engine-environment-$DYNAMIC_ENGINE_ENVIRONMENT_ID \
     oci://ghcr.io/talend/helm/dynamic-engine-environment \
     --version ${DYNAMIC_ENGINE_VERSION} \
     -f $DYNAMIC_ENGINE_ENVIRONMENT_ID-values.yaml
   ```

   Replace ${DYNAMIC\_ENGINE\_VERSION} with your environment's version.

   This command creates the Dynamic Engine environment and its associated namespace qlik-processing-env-$DYNAMIC\_ENGINE\_ENVIRONMENT\_ID.
4. Create the ConfigMap in your Dynamic Engine environment namespace.
   ```
   kubectl apply -f configmap-external-config.yaml
   ```

   This command creates the ConfigMap resource in your Kubernetes cluster. The ConfigMap is available for use by all pods in the environment namespace.
5. Upgrade your Dynamic Engine environment with the ConfigMap configuration.
   ```
   helm upgrade dynamic-engine-environment-$DYNAMIC_ENGINE_ENVIRONMENT_ID \
     oci://ghcr.io/talend/helm/dynamic-engine-environment \
     --version ${DYNAMIC_ENGINE_VERSION} \
     -f $DYNAMIC_ENGINE_ENVIRONMENT_ID-values.yaml \
     -f configmap-values.yaml
   ```

   Replace ${DYNAMIC\_ENGINE\_VERSION} with your environment's version.

   This command applies your ConfigMap configuration to the Dynamic Engine environment. The environment variables become available to all deployed tasks.
6. Verify that environment variables from the ConfigMap are available in running pods.
   ```
   kubectl get pod -n qlik-processing-env-$DYNAMIC_ENGINE_ENVIRONMENT_ID <pod-name> \
     -o jsonpath='{.spec.containers[*].envFrom}'
   ```

   Expected output should include the ConfigMap reference:
   ```
   [{"configMapRef":{"name":"external-config"}}]
   ```

## Results

Your Dynamic Engine environment provides access to configuration from your Kubernetes ConfigMap as environment variables.

When you update the variables in your ConfigMap, the changes are applied as follows:

* Jobs (Data Integration, including Big Data tasks) are one-time tasks. Updated values are read when the next task run starts.
* Routes and Data Services are always-on tasks; they do not automatically reload ConfigMap changes. [Update the task in Talend Management Console](https://help.qlik.com/talend/en-US/dynamic-engine-configuration-guide/Cloud/updating-data-service-and-route-tasks-in-dee "You can update the artifact version or change the configuration of a Data service or Route task deployed in a Dynamic Engine environment without downtime.") to trigger a re-deployment in your Dynamic Engine environment.