Adding Connections, Variables and Environment Variables

You can programmatically add Connections, Variables and arbitrary Environment Variables to your Airflow deployment using the Helm Chart.

Connections and Sensitive Environment Variables

Under the secret and extraSecret sections of the values.yaml, you can pass connection strings and sensitive environment variables into Airflow using the Helm Chart. To illustrate, lets create a yaml file called override.yaml to override values under these sections of the values.yaml file.

override.yaml
secret:
  - envName: "AIRFLOW_CONN_GCP"
    secretName: "my-airflow-connections"
    secretKey: "AIRFLOW_CONN_GCP"
  - envName: "my-env"
    secretName: "my-secret-name"
    secretKey: "my-secret-key"

extraSecrets:
  my-airflow-connections:
    data: |
      AIRFLOW_CONN_GCP: 'base64_encoded_gcp_conn_string'
  my-secret-name:
    stringData: |
      my-secret-key: my-secret

Warning

Due to security concerns, it is not advised to define sensitive secrets values within values.yaml file.

Variables

Airflow supports Variables which enable users to craft dynamic Dags. You can set Variables in Airflow in three ways - UI, command line, and within your Dag file. See Managing Variables for more.

With the Helm Chart, you can also inject environment variables into Airflow. In the override.yaml example file, we can override values of interest in the env section of the values.yaml file.

override.yaml
env:
  - name: "AIRFLOW_VAR_KEY"
    value: "value_1"
  - name: "AIRFLOW_VAR_ANOTHER_KEY"
    value: "value_2"

You can also utilize extraEnv and extraEnvFrom if you need the name or value to be templated.

override.yaml
extraEnv: |
  - name: AIRFLOW_VAR_HELM_RELEASE_NAME
    value: '{{ .Release.Name }}'

extraEnvFrom: |
  - configMapRef:
      name: '{{ .Release.Name }}-airflow-variables'

extraConfigMaps:
  '{{ .Release.Name }}-airflow-variables':
    data: |
      AIRFLOW_VAR_HELLO_MESSAGE: "Hi!"

Was this entry helpful?