Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Airflow KubernetesPodOperator - using a ConfigMap value as an environmental variable

I have a Kubernetes ConfigMap called test that contains a key foobar with some value. I would like to use that key's value in an environmental variable.

import datetime
import os
from airflow import models
from airflow.contrib.kubernetes.volume import Volume
from airflow.contrib.kubernetes.volume_mount import VolumeMount
from airflow.contrib.operators import kubernetes_pod_operator

YESTERDAY = datetime.datetime.now() - datetime.timedelta(days=1)

cm_test = ['test']

volume_mount = VolumeMount('test',
                            mount_path='/config/',
                            sub_path=None,
                            read_only=False)
volume_config = {
    'configMap': {
        'name': 'test'
    }
}
volume = Volume(name='test', configs=volume_config)

with models.DAG(
        dag_id="test_env",
        schedule_interval=datetime.timedelta(days=1),
        start_date=YESTERDAY) as dag:

    
    kubenetes_template_ex = kubernetes_pod_operator.KubernetesPodOperator(
        task_id="test_env",
        name="test_env",
        namespace="foobar",
        image="bash",
        cmds=["printenv"],
        arguments=[],
        volumes=[volume],
        volume_mounts=[volume_mount],
        configmaps=cm_test,
        env_vars={
            'MY_ENV_VAR': '/config/foobar'
        }
    )

What's working: the ConfigMap is available in the mounted volume, so I can do ls /config and foobar is shown.

What's not working: I would like to set an environmental variable with the value from foobar from the mounted configmap. The current code doesn't work, as the literal string value /config/foobar is given to the env var.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!