如何让我的R文件(从KubernetesPodOperator启动)在气流中查看我的kubernetes环境变量?
请一直向下滚动 我有一个dag在气流中运行,启动三个KubernetesPodOperators,所有这些操作员都启动R文件。所以,在过去的几天里,我对R有很多问题,让它看到环境变量。我让我的db用户名和密码成为我的R文件可以看到的环境变量,但无论我做什么,它都看不到 到目前为止我一直在尝试的内容:起初,我制作了一个ConfigMaps和一个Secrets文件,并尝试用我的R文件实现它,但我可能做得完全错误(如果你没有注意到,我对kubernetes和airflow非常陌生)。之后,我尝试将环境变量放置在airflow docker容器的helm图表的如何让我的R文件(从KubernetesPodOperator启动)在气流中查看我的kubernetes环境变量?,r,docker,kubernetes,airflow,R,Docker,Kubernetes,Airflow,请一直向下滚动 我有一个dag在气流中运行,启动三个KubernetesPodOperators,所有这些操作员都启动R文件。所以,在过去的几天里,我对R有很多问题,让它看到环境变量。我让我的db用户名和密码成为我的R文件可以看到的环境变量,但无论我做什么,它都看不到 到目前为止我一直在尝试的内容:起初,我制作了一个ConfigMaps和一个Secrets文件,并尝试用我的R文件实现它,但我可能做得完全错误(如果你没有注意到,我对kubernetes和airflow非常陌生)。之后,我尝试将环境
config
部分。这不起作用,所以我尝试将环境变量直接放在aiffort.cfg中,这也不起作用
我现在要做的是:我想我可能需要在我的dag中注入KubernetesPodOperator,让我的R文件看到这些环境变量,所以我尝试制作一个kubernetes secrets文件,并将其放在我的dag文件中,以便启动的pod可以看到它,但我甚至不确定我是否做得正确。我试着做这家伙做的事:但当吊舱启动时,我总是收到集装箱确认错误
另外,如果我的pod可以看到环境变量,那么这是否意味着它里面的R文件也可以肯定地看到它们
这就是我如何在airflow的helm图表配置中放置环境变量的方法
## Custom airflow configuration environment variables
## Use this to override any airflow setting settings defining environment variables in the
## following form: AIRFLOW__<section>__<key>.
## See the Airflow documentation: https://airflow.readthedocs.io/en/stable/howto/set-config.html?highlight=setting-configuration
## Example:
## config:
## AIRFLOW__CORE__EXPOSE_CONFIG: "True"
## HTTP_PROXY: "http://proxy.mycompany.com:123"
config: {
ANOTHER_TEST: "MORE TESTING!!!",
AIRFLOW__KUBERNETES_ENVIRONMENT_VARIABLES__FETCHDB_DB: "postgres",
TEST: "testing!!!!!!!!!!!!"
}
我的秘密似乎很好:
root@ip-10-30-35-195:# kubectl describe secret/fetchdb-secret
Name: fetchdb-secret
Namespace: default
Labels: <none>
Annotations:
Type: Opaque
Data
====
password: 12 bytes
username: 5 bytes
相反,吊舱应该正常运行。如果我注释掉python文件中的secrets=…
,则pod不会失败
另外,我在执行kubectl获取pods
时遇到的错误:
fetch-db-f226395c 0/1 CreateContainerConfigError 0 17m
我该怎么办
编辑:我用CreateContainerConfigError
在pod上描述了kubectl的pod,这就是我得到的:
Name: fetch-db-f226395c
Namespace: airflow
Priority: 0
Node: ip-10-30-35-195/10.30.35.195
Start Time: Wed, 31 Jul 2019 15:00:33 +0000
Labels: <none>
Annotations: <none>
Status: Pending
IP: 10.1.1.184
Containers:
base:
Container ID:
Image: localhost:32000/zz/z
Image ID:
Port: <none>
Host Port: <none>
Args:
Rscript
/home/ruser/fetch_db.R
zzz
manual__2019-07-31T15:00:27.227397+00:00
1
State: Waiting
Reason: CreateContainerConfigError
Ready: False
Restart Count: 0
Environment:
FETCHDB_USERNAME: <set to the key 'username' in secret 'fetchdb-secret'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9nl85 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-9nl85:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9nl85
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 3m47s (x683 over 153m) kubelet, ip-10-30-35-195 Pulling image "localhost:32000/zz/z"
名称:fetch-db-f226395c
名称空间:气流
优先级:0
节点:ip-10-30-35-195/10.30.35.195
开始时间:2019年7月31日星期三15:00:33+0000
标签:
注释:
状态:待定
IP:10.1.1.184
容器:
基数:
容器ID:
图片:localhost:32000/zz/z
图像ID:
端口:
主机端口:
Args:
Rscript
/home/ruser/fetch_db.R
zzz
手册2019-07-31T15:00:27.227397+00:00
1.
国家:等待
原因:CreateContainerConfiger错误
就绪:错误
重新启动计数:0
环境:
FETCHDB_用户名:可选:false
挂载:
/来自default-token-9nl85(ro)的var/run/secrets/kubernetes.io/serviceCount
条件:
类型状态
初始化为True
准备错误
集装箱准备好了吗
播客预定为真
卷数:
default-token-9nl85:
类型:Secret(由Secret填充的卷)
SecretName:default-token-9nl85
可选:false
QoS等级:最佳努力
节点选择器:
容差:node.kubernetes.io/未就绪:不执行300秒
node.kubernetes.io/不可访问:不执行300秒
活动:
从消息中键入原因年龄
---- ------ ---- ---- -------
正常拉动3m47s(x683超过153m)kubelet,ip-10-30-35-195拉动图像“本地主机:32000/zz/z”
所以,看起来这个秘密被正确地注入了,但它仍然导致了一个错误
编辑2:看来问题毕竟是由我的秘密引起的。与创建fetch db pod的名称空间相比,我的秘密位于不同的名称空间中
编辑3:我的最后一个问题是,如何准确地将ConfigMaps注入我的KubernetesPodOperators?我制作了一个ConfigMap和所有这些,但R似乎看不到这些变量。您似乎忘记了错误抱歉,修复了这个问题。
fetch-db-f226395c 0/1 CreateContainerConfigError 0 17m
Name: fetch-db-f226395c
Namespace: airflow
Priority: 0
Node: ip-10-30-35-195/10.30.35.195
Start Time: Wed, 31 Jul 2019 15:00:33 +0000
Labels: <none>
Annotations: <none>
Status: Pending
IP: 10.1.1.184
Containers:
base:
Container ID:
Image: localhost:32000/zz/z
Image ID:
Port: <none>
Host Port: <none>
Args:
Rscript
/home/ruser/fetch_db.R
zzz
manual__2019-07-31T15:00:27.227397+00:00
1
State: Waiting
Reason: CreateContainerConfigError
Ready: False
Restart Count: 0
Environment:
FETCHDB_USERNAME: <set to the key 'username' in secret 'fetchdb-secret'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9nl85 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-9nl85:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9nl85
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulling 3m47s (x683 over 153m) kubelet, ip-10-30-35-195 Pulling image "localhost:32000/zz/z"