【问题标题】:How to setup Kubernetes Executor on Airflow 2.x running Locally on Ubuntu-- NO HELM CHART如何在 Ubuntu 上本地运行的 Airflow 2.x 上设置 Kubernetes Executor——没有 HELM CHART
【发布时间】:2022-01-21 06:01:43
【问题描述】:

谁能告诉我如何在本地气流部署中配置 kuberenetes 执行器。我创建了一个名为airflow-cluster 的类集群并创建了pod_template.yaml,并在airflow.cfg 中进行了以下更改。

[kubernetes]
# Path to the YAML pod file that forms the basis for KubernetesExecutor workers.
pod_template_file = /home/caxe/airflow/logs/yamls/pod_template.yaml
worker_container_repository = apache/airflow
worker_container_tag = 2.2.3
namespace = airflow
in_cluster = False
cluster_context = kind-airflow-cluster
config_file = /home/caxe/.kube/config

pod_template.yaml

---
apiVersion: v1
kind: Pod
metadata:
  name: dummy-name
spec:
  containers:
    - env:
        - name: AIRFLOW__CORE__EXECUTOR
          value: LocalExecutor
        # Hard Coded Airflow Envs
        - name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
          value: postgresql+psycopg2://airflow:airflow@localhost:5432/airflow
      image: apache/airflow:2.2.3
      imagePullPolicy: IfNotPresent
      name: base
      volumeMounts:
        - mountPath: "/opt/airflow/logs"
          name: airflow-logs
        - mountPath: "/opt/airflow/dags"
          name: airflow-dags
          readOnly: true
        - mountPath: "/opt/airflow/airflow.cfg"
          name: airflow-config
          readOnly: true
          subPath: airflow.cfg
  restartPolicy: Never
  securityContext:
    runAsUser: 50000
    fsGroup: 50000
  serviceAccountName: airflow
  volumes:
    - name: airflow-logs
      persistentVolumeClaim:
        claimName: logs-pv-claim
    - name: airflow-dags
      persistentVolumeClaim:
        claimName: dag-pv-claim
    - configMap:
        name: k8s-config 
      name: airflow-config

不执行。正在运行kubectl get pods -n airflow

NAME                                                               READY   STATUS    RESTARTS   AGE
examplebashoperatoralsorunthis.dd577351d4554c87923bc1eabe5e617e    0/1     Pending   0          114s
examplebashoperatorrunme0.afd364b8033643549a29ab536e9fc83f         0/1     Pending   0          116s
examplebashoperatorrunme1.47c97859639543bcab04a2ef0001ee9a         0/1     Pending   0          116s
examplebashoperatorrunme2.7296c3f011624f5ab62c1777187a006f         0/1     Pending   0          115s
examplebashoperatorthiswillskip.b9474f2673524a538ed2fddb6af00dd0   0/1     Pending   0          113s

我不是 kubernetes 人,我已经创建了持久卷并声明了日志和 dag,但我认为非集群 postgres 连接可能存在问题。因为除了在 config 和 yaml 文件中提供值之外,我还没有在集群中配置 postgres。此外,psycopg2 (apache-airflow[postgres]) 安装在本地气流中,但由于我没有修改基本图像apace/airflow:2.2.3,它会丢失吗?

【问题讨论】:

  • 我已经取得了相当大的进步。马上分享!!!现在处理日志

标签: linux airflow ubuntu-20.04 airflow-2.x


【解决方案1】:

设置 Kubernetes Executor 需要 Postgres 在集群中作为服务运行并转发端口,以便 Executor pod 可以访问它。它还需要通过创建 Dockerfile 并使用气流的基本映像来安装附加包 apache-airflow['postgres']。我们还必须创建持久卷和持久卷声明,以存储我们的 dag 和日志。确保我们使用的图像与我们本地系统中的 python 版本相同。

requirements.txt

apache-airflow-providers-cncf-kubernetes==3.0.1
apache-airflow-providers-postgres==2.4.0

Dockerfile

FROM apache/airflow:2.2.3-python3.8 
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY test.py /opt/airflow/dags/

使用标签创建自定义图像,例如。 airflow-custom:1.0.0 使用 docker build -t airflow-custom:1.0.0 . 并在 pod 模板文件中指定它。

【讨论】:

    猜你喜欢
    • 2020-01-26
    • 2020-05-28
    • 2021-03-01
    • 2020-04-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 2019-10-12
    相关资源
    最近更新 更多