首页 > 解决方案 > Kubernetes 上的 Airflow:Pod 能够在 PostgreSql 上运行 initdb,但随后的 create_user 以 SQLite 为目标

问题描述

我正在使用本地 Kubernetes 集群中的 Helm Chart 在 Kubernetes 中设置 Apache Airflow,作为 Docker Desktop 的一部分提供。

在 Helm 图表中,我有:

在此处输入图像描述

Webserver 和 Scheduler 的 Pod 能够成功连接到运行 PostgreSql 的 Pod。但是 Jobs.yaml 中定义的批处理作业得到“连接被拒绝”。

供应商 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 中创建用户。

标签: postgresqlkubernetesairflowkubernetes-helm

解决方案


好吧,对于那些提出这个问题的人——我最终放弃了我最初的方法(用于初始化 Airflow DB 和用户的 Kubernetes 批处理作业),而是克隆了官方的Airflow Helm 图表并进行了一些更改。


推荐阅读