For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
      • AstroFully-managed data operations, powered by Apache Airflow.
      • Astro Private CloudRun Airflow-as-a-service in your environment.
      • Professional ServicesExpert Airflow services for your enterprise's success.
    • Tools
      • Cosmos
      • Orbiter
      • CLI
      • AI SDK
      • Agents
      • Blueprint
      • UpdatesThe State of Airflow 2026See the insights from over 5,800 data practitioners in the full report. Download Now ➔
  • Customers
  • Docs
    • Insights
      • Blog
      • Webinars
      • Resource Library
      • Events
    • Education
      • Academy
      • What is Airflow?
  • Pricing
Get Started Free
    • Overview
      • Overview
        • Set up KubernetesPodOperator
        • Configure task-level resources
        • Mount a temporary directory
        • Run your Deployment's current Airflow image
        • Use secret environment variables
        • Use the @task.kubernetes decorator
      • Dag versioning
      • Airflow logs
      • DAG and task runs
      • Airflow REST API
    • Book Office Hours

Product

  • Platform Overview
  • Astro
  • Astro Observe
  • Astro Private Cloud
  • Security & Trust
  • Pricing

Tools & Services

  • Cosmos
  • Docs
  • Professional Services
  • Product Updates

Use Cases

  • AI Ops
  • Data Observability
  • ETL/ELT
  • ML Ops
  • Operational Analytics
  • All Use Cases

Industries

  • Financial Services
  • Gaming
  • Retail
  • Manufacturing
  • Healthcare
  • All Industries

Resources

  • Academy
  • eBooks & Guides
  • Blog
  • Webinars
  • Events
  • The Data Flowcast Podcast
  • All Resources

Airflow

  • What is Airflow
  • Airflow on Astro
  • Airflow 3.0
  • Airflow Upgrades
  • Airflow Use Cases
  • Airflow 2.x End of Life

Company

  • Our Story
  • Customers
  • Newsroom
  • Careers
  • Contact

Support

  • Knowledge Base
  • Status
  • Contact Support
GitHubYouTubeLinkedInx
  • Legal
  • Privacy
  • Terms of Service
  • Consent Preferences

  • Do Not Sell or Share My Personal information
  • Limit the Use Of My Sensitive Personal Information

Apache Airflow®, Airflow, and the Airflow logo are trademarks of the Apache Software Foundation. Copyright © Astronomer 2026. All rights reserved.

LogoLogo
On this page
  • Setup
  • Example
Develop DAGsKubernetesPodOperator

Use secret environment variables

Edit this page
Built with

Astro environment variables marked as secrets are stored in a Kubernetes secret called env-secrets. To use a secret value in a task running on the Kubernetes executor, you pull the value from env-secrets and mount it to the Pod running your task as a new Kubernetes Secret.

Setup

1

Add import to your dag file

Add the Secret import to your dag file:

1from airflow.kubernetes.secret import Secret
2

Define a Kubernetes secret

Define a Kubernetes Secret in your dag instantiation using the following format:

1secret_env = Secret(deploy_type="env", deploy_target="<VARIABLE_KEY>", secret="env-secrets", key="<VARIABLE_KEY>")
2namespace = conf.get("kubernetes", "NAMESPACE")
3

Reference the environment variable key

Reference the key for the environment variable, formatted as $VARIABLE_KEY in the task using the KubernetesPodOperator.

Example

In the following example, a secret named MY_SECRET is pulled from env-secrets and printed to logs.

1import pendulum
2from airflow.kubernetes.secret import Secret
3
4from airflow.models import DAG
5from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
6from airflow.configuration import conf
7
8with dag(
9 dag_id='test-kube-pod-secret',
10 start_date=pendulum.datetime(2022, 1, 1, tz="UTC"),
11 end_date=pendulum.datetime(2022, 1, 5, tz="UTC"),
12 schedule_interval="@once",
13) as dag:
14
15 secret_env = Secret(deploy_type="env", deploy_target="MY_SECRET", secret="env-secrets", key="MY_SECRET")
16
17 namespace = conf.get("kubernetes", "NAMESPACE")
18
19 k = KubernetesPodOperator(
20 namespace=namespace,
21 image="ubuntu:16.04",
22 cmds=["bash", "-cx"],
23 arguments=["echo $MY_SECRET && sleep 150"],
24 name="test-name",
25 task_id="test-task",
26 get_logs=True,
27 in_cluster=True,
28 secrets=[secret_env],
29 )