Airflow KubernetesPodOperator:如何访问传递给Pod的秘密?

问题描述

我试图在气流中将秘密变量传递给我的 KubernetesPodoperator

这是我所做的:

  1. 创建一个如下所示的 secret.yaml 文件
apiVersion: v1
kind: Secret
Metadata:
  name: my-secret
type: Opaque
data:
  SECRET_1: blabla 
  SECRET_2: blibli 
  1. 应用秘密:
kubectl apply -f ./secret.yaml
  1. 从我的 DAG 文件中检索机密:
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="env",deploy_target="SECRET_1",secret="ai-controller-object-storage",key="SECRET_1"
)
SECRET_2 = Secret(
   deploy_type="env",deploy_target="SECRET_2",key="SECRET_2"
)

with DAG(...) as dag:
   KubernetesPodoperator(
           task_id=..,trigger_rule="all_success",namespace="default",image=IMAGE,startup_timeout_seconds=600,secrets=[
               SECRET_1,SECRET_2],...)

所以现在据我所知,我应该从 SECRET_1

访问 KubernetesPodoperator 作为容器中的环境变量

但是,我从 python 脚本(使用 os.environ["SECRET_1"])执行的第一个任务返回一个错误,表明该环境变量不存在:

KeyError: 'SECRET_1'

我怎样才能从我的 python 脚本访问这个变量?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)