我试图在气流中将秘密变量传递给我的 KubernetesPodOperator
这是我所做的:
secret.yaml
文件apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
data:
SECRET_1: blabla
SECRET_2: blibli
kubectl apply -f ./secret.yaml
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", secret="ai-controller-object-storage", 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 脚本访问这个变量?