title: Airflow KubernetesPodOperator : how to access secret passed to Pod?
body: <p>I am trying to pass secret variables to my <code>KubernetesPodOperator</code> in airflow</p>
  <p>Here is what I have done :</p>
  <ol>
  <li>Create a <code>secret.yaml</code> file that looks like the following</li>
  </ol>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
  kind: Secret
  metadata:
    name: my-secret
  type: Opaque
  data:
    SECRET_1: blabla 
    SECRET_2: blibli 
  </code></pre>
  <ol start="2">
  <li>Apply the secret :</li>
  </ol>
  <pre class="lang-sh prettyprint-override"><code>kubectl apply -f ./secret.yaml
  </code></pre>
  <ol start="3">
  <li>Retrieve the secret from my DAG file :</li>
  </ol>
  <pre class="lang-py prettyprint-override"><code>from airflow.contrib.kubernetes.secret import Secret
  from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
  from airflow.models import DAG
  
  SECRET_1 = Secret(
     deploy_type=&quot;env&quot;, deploy_target=&quot;SECRET_1&quot;, secret=&quot;ai-controller-object-storage&quot;, key=&quot;SECRET_1&quot;
  )
  SECRET_2 = Secret(
     deploy_type=&quot;env&quot;, deploy_target=&quot;SECRET_2&quot;, secret=&quot;ai-controller-object-storage&quot;, key=&quot;SECRET_2&quot;
  )
  
  with DAG(...) as dag:
     KubernetesPodOperator(
             task_id=..,
             trigger_rule=&quot;all_success&quot;,
             namespace=&quot;default&quot;,
             image=IMAGE,
             startup_timeout_seconds=600,
             secrets=[
                 SECRET_1,
                 SECRET_2], ...)
  </code></pre>
  <p>So now as I understand, I should access <code>SECRET_1</code> as environnement variable in my container from <code>KubernetesPodOperator</code></p>
  <p>However my first task from a python script (with <code>os.environ[&quot;SECRET_1&quot;]</code>) returns an error that indicates that this environment variable does not exist :</p>
  <pre><code>KeyError: 'SECRET_1'
  </code></pre>
  <p>How can I access this variable from my python script then ?</p>