postgresql - Kubernetes 上的 Airflow:Pod 能够在 PostgreSql 上运行 initdb,但随后的 create_user 以 SQLite 为目标
问题描述
我正在使用本地 Kubernetes 集群中的 Helm Chart 在 Kubernetes 中设置 Apache Airflow,作为 Docker Desktop 的一部分提供。
在 Helm 图表中,我有:
- Requirements.yaml -> PostgreSql (Bitnami Helm Chart)
- 部署-Web.yaml -> 气流网络服务器
- Deployments-Scheduler.yaml -> 气流调度器
- Jobs.yaml -> 配置作业以运行气流 initdb、create_user 等。
Webserver 和 Scheduler 的 Pod 能够成功连接到运行 PostgreSql 的 Pod。但是 Jobs.yaml 中定义的批处理作业得到“连接被拒绝”。
- 所有 pod 的 SQLAlchemy 连接字符串都相同
- 如果我将参数从 Jobs.yaml 移动到任意的第三个部署,它就可以工作 - 我能够连接到运行 PostgreSql 的 Pod。但由于我只想运行一次,所以我想把它作为一项工作。
供应商 pod 上的错误:
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "orchestrator-postgresql" (10.105.92.200) and accepting
TCP/IP connections on port 5432?
kubectl describe pod
对于失败的 pod 给出:
Name: orchestrator-provisioner-9d77p Namespace: orchestrator Priority: 0 Node: docker-desktop/192.168.65.3 Start Time: Thu, 03 Sep 2020 15:04:56 +0200 Labels: controller-uid=09661ecd-f8da-4c76-9c9b-4d2e80cf8253
job-name=orchestrator-provisioner Annotations: <none> Status: Failed IP: 10.1.0.221 IPs: IP:
10.1.0.221 Controlled By: Job/orchestrator-provisioner Containers: provisioner:
Container ID: docker://eeee02787b323f2991d91347b1ae306a7d0c4935fa49ee738fc91c64b020f18e
Image: xxx
Image ID: docker://sha256:d2ebf8eefd15abe77b979bb281820c6f7c3a073e16716ad5c3b51b660e140081
Port: <none>
Host Port: <none>
Args:
airflow initdb;
sleep 10;
airflow create_user \
--role Admin \
--username airflow \
--password airflow \
--firstname Air \
--lastname Flow \
--email air.flow@examle.com;
State: Terminated
Reason: Error
Exit Code: 1
Started: Thu, 03 Sep 2020 15:04:56 +0200
Finished: Thu, 03 Sep 2020 15:05:16 +0200
Ready: False
Restart Count: 0
Environment Variables from:
orchestrator-secrets Secret Optional: false
orchestrator-env ConfigMap Optional: false
Environment:
AIRFLOW_KUBE_NAMESPACE: orchestrator
Mounts:
/usr/local/airflow/airflow.cfg from airflow-config (rw,path="airflow.cfg")
/var/run/secrets/kubernetes.io/serviceaccount from default-token-glzmg (ro) Conditions: Type Status Initialized True Ready False ContainersReady False PodScheduled True Volumes: airflow-config:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: orchestrator-config
Optional: false default-token-glzmg:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-glzmg
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:
关于可能出错的任何提示?
编辑:发现问题所在。在第一次尝试运行批处理作业时,PostgreSql Pod 已启动,但服务未启动。所以端口仍然没有打开,导致连接被拒绝。在 Batch Job 第二次运行时,成功初始化 PostgreSql 中的元数据 DB。
但是现在我面临另一个问题。在initdb之后,我正在运行气流 create_user。由于某种原因,这个无法获取包含 SQLAlchemy 连接字符串的环境变量,而是继续尝试在 SQLite DB 中创建用户。
解决方案
好吧,对于那些提出这个问题的人——我最终放弃了我最初的方法(用于初始化 Airflow DB 和用户的 Kubernetes 批处理作业),而是克隆了官方的Airflow Helm 图表并进行了一些更改。
推荐阅读
- database - Postgres - 将来自 2 个不同表的数据组合到 1 个表中
- json - 将json中的时间戳对象转换为字符串形式的时间戳
- laravel - 如何从 Google Analytics 4 中获取视图 ID?
- c# - 生成 PDF 时的古吉拉特语 托管 AWS Server ASP.NET 不支持
- python - 在 python 3.9 中安装 cvlib 包
- python - Divmod() 逻辑将克转换为公斤、磅、盎司
- r - R:NbClust 包使用具有随机行顺序的相同数据集给出不同的最佳聚类数
- php - PHP登录在提交时重新加载
- vue.js - nuxt auth 在登录前调用用户并给出 401
- python - 错误 - ValueError:权重的数量与 python 3 中的总体不匹配