【问题标题】:Helm stable/airflow - Custom values for Airflow deployment with Shared Persistent Volume using Helm chart failingHelm stable/airflow - 使用 Helm 图表失败的具有共享持久卷的 Airflow 部署的自定义值
【发布时间】:2020-02-06 13:02:23
【问题描述】:

目标

我想在 Kubernetes 上部署 Airflow,其中 pod 可以在共享持久卷中访问相同的 DAG。 根据文档 (https://github.com/helm/charts/tree/master/stable/airflow#using-one-volume-for-both-logs-and-dags),看来我必须设置这些值并将其传递给 Helm:extraVolumeextraVolumeMountpersistence.enabledlogsPersistence.enableddags.pathlogs.path

问题

我在安装官方 Helm 图表时传递的任何自定义值都会导致类似以下错误:

Error: YAML parse error on airflow/templates/deployments-web.yaml: error converting YAML to JSON: yaml: line 69: could not find expected ':'
  • 工作正常:microk8s.helm install --namespace "airflow" --name "airflow" stable/airflow
  • 不工作
microk8s.helm install --namespace "airflow" --name "airflow" stable/airflow \
--set airflow.extraVolumes=/home/*user*/github/airflowDAGs \
--set airflow.extraVolumeMounts=/home/*user*/github/airflowDAGs \
--set dags.path=/home/*user*/github/airflowDAGs/dags \
--set logs.path=/home/*user*/github/airflowDAGs/logs \
--set persistence.enabled=false \
--set logsPersistence.enabled=false
  • 也不工作microk8s.helm install --namespace "airflow" --name "airflow" stable/airflow --values=values_pv.yamlvalues_pv.yamlhttps://pastebin.com/PryCgKnC
    • 编辑:请将/home/*user*/github/airflowDAGs 更改为您机器上的路径以复制错误。

疑虑

  1. 可能因为默认values.yaml中的这些行而出错:
## Configure DAGs deployment and update
dags:
  ##
  ## mount path for persistent volume.
  ## Note that this location is referred to in airflow.cfg, so if you change it, you must update airflow.cfg accordingly.
  path: /home/*user*/github/airflowDAGs/dags

如何在 Kubernetes 部署中配置 airflow.cfg?在 Airflow 的非容器化部署中,可以在 ~/airflow/airflow.cfg 中找到此文件。

  1. airflow.cfg 中的第 69 行指的是:https://github.com/helm/charts/blob/master/stable/airflow/templates/deployments-web.yaml#L69

其中包含git.yaml是不是配置错误,误用git pull,但是由于没有指定git路径,所以失败了?

系统

  • 操作系统:Ubuntu 18.04(单机)
  • MicroK8s:v1.15.4 Rev:876
  • microk8s.kubectl version: v1.15.4
  • microk8s.helm version: v2.14.3

问题

如何正确地将正确的值传递给 Airflow Helm 图表,以便能够在 Kubernetes 上部署 Airflow,Pod 可以访问相同的 DAG 并在共享持久卷上登录?

【问题讨论】:

  • Meaby 而不是尝试在 values.yaml 中更改 --set extraVolume 和 extraVolumeMount?你试过这样做吗? github.com/helm/charts/blob/master/stable/airflow/…
  • @jt97 是的,那是我的另一次尝试。这是问题中带有values_pv.yaml 的要点(pastebin.com/PryCgKnC)。我假设重命名 values.yaml 对功能没有影响。
  • @NumesSanguis 你能设置卷挂载吗?
  • @alltej 我没有时间做我的项目,而且它实际上不需要 Kubernetes,所以我选择了一个更简单的解决方案。此外,Helm 3.0 已经发布,这意味着答案可能会改变。希望以后有机会再试。

标签: kubernetes airflow kubernetes-helm microk8s


【解决方案1】:

不确定你是否已经解决了这个问题,但如果你还没有,我认为有一个非常简单的方法接近你正在做的事情。

所有的 Deployment、Service、Pod 都需要持久化卷信息——它在本地的位置以及在每个 kube 类型中的位置。看起来图表的 values.yaml 提供了一种方法来做到这一点。我只会在下面用 dags 展示这个,但我认为它也应该与日志的过程大致相同。

所以基本步骤是,1)告诉 kube '卷'(目录)在你的计算机上的位置,2)告诉 kube 将它放在你的容器中的哪个位置,以及 3)告诉气流在哪里寻找 dag。因此,您可以从 helm repo 中复制 values.yaml 文件并使用以下内容进行更改。

  1. airflow 部分

首先,您需要创建一个包含本地目录中项目的卷(这是下面的extraVolumes)。然后,需要挂载它——幸运的是,把它放在这里会将它模板化到所有 kube 文件中。创建该卷后,您应该告诉它挂载dags。所以基本上,extraVolumes 创建卷,extraVolumeMounts 挂载卷。

airflow:
  extraVolumeMounts: # this will get the volume and mount it to that path in the container                                                                                                                                                               
  - name: dags
    mountPath: /usr/local/airflow/dags  # location in the container it will put the directory mentioned below.

  extraVolumes: # this will create the volume from the directory
  - name: dags
    hostPath:
      path: "path/to/local/directory"  # For you this is something like /home/*user*/github/airflowDAGs/dags

  1. 告诉气流配置 dags 在容器中的位置(与上面相同的 yaml 部分)。
airflow:
  config:
    AIRFLOW__CORE__DAGS_FOLDER: "/usr/local/airflow/dags"  # this needs to match the mountPath in the extraVolumeMounts section
  1. 使用 helm 和您的新 values.yaml 文件安装。
helm install --namespace "airflow" --name "airflow" -f local/path/to/values.yaml stable/airflow

最后,这应该允许气流在 dags 文件夹中查看您的本地目录。如果您添加一个新文件,它应该会显示在容器中 - 尽管可能需要一分钟才能显示在 UI 中 - 我认为 dagbag 进程不会一直在运行?无论如何,希望这会有所帮助!

【讨论】:

  • 当 DAG 存储在外部卷(共享持久卷)中时,您将如何设置 extraVolumes
  • 我没有得到关于在extraVolumes 中设置hostPath.path 的部分:path: "path/to/local/directory"
  • 我相信如果它已经在一个卷中,你可以使用 extraVolumeMounts 并且它的名称应该与你正在安装的卷相对应。 hostPath.path 将用于添加本地代码——实际上是本地机器或主机上的目录。如果您的代码已经在一个卷中,您可以通过 extraVolumeMounts 部分将其传递。
【解决方案2】:

用 yaml 文件来做

因此,如果我们考虑使用 values.yaml,就会出现问题,因为您以错误的方式编辑它。

extraVolumeMounts: home/*user*/github/airflowDAGs
  ## Additional volumeMounts to the main containers in the Scheduler, Worker and Web pods.
  # - name: synchronised-dags
  #   mountPath: /usr/local/airflow/dags
  extraVolumes: home/*user*/github/airflowDAGs
  ## Additional volumes for the Scheduler, Worker and Web pods.
  # - name: synchronised-dags
  #   emptyDir: {}

如果 extraVolumeMounts 需要 namemounthPath 工作,你不能只传递这样的路径,这就是你在那里有# 的原因,所以你可以删除他们,添加你的价值观,它应该工作。

应该是这样的

 extraVolumeMounts:
 - name: synchronised-dags
   mountPath: /usr/local/airflow/dags
 extraVolumes:
 - name: synchronised-dags
   emptyDir: {}

你可以这样安装它:

1.使用 helm fetch 下载气流图到你的电脑

helm fetch stable/airflow --untar

2.像上面的例子一样编辑airflow/values.yaml extraVolumeMount and extraVolume,只需添加你的名字和路径。

nano/vi/vim airflow/values.yaml

3.您可以更改气流/values.yaml 中的其余内容并使用:

helm install ./airflow --namespace "airflow" --name "airflow" -f ./airflow/values.yaml

使用此命令只编辑 extraVolumeMount 和 extraVolume

helm install --set dags.path=/home/user/github/airflowDAGs/dags --set logs.path=/home/user/github/airflowDAGs/logs --set persistence.enabled=false --set logsPersistence.enabled=false  ./airflow --namespace "airflow" --name "airflow" -f ./airflow/values.yaml

结果:

NAME:   airflow
LAST DEPLOYED: Fri Oct 11 09:18:46 2019
NAMESPACE: airflow
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                  DATA  AGE
airflow-env           20    2s
airflow-git-clone     1     2s
airflow-postgresql    0     2s
airflow-redis         3     2s
airflow-redis-health  3     2s
airflow-scripts       1     2s

==> v1/Deployment
NAME               READY  UP-TO-DATE  AVAILABLE  AGE
airflow-flower     0/1    1           0          1s
airflow-scheduler  0/1    1           0          1s
airflow-web        0/1    1           0          1s

==> v1/PersistentVolumeClaim
NAME                STATUS   VOLUME    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
airflow-postgresql  Pending  standard  2s

==> v1/Pod(related)
NAME                                 READY  STATUS             RESTARTS  AGE
airflow-flower-5596b45d58-wrg74      0/1    ContainerCreating  0         1s
airflow-postgresql-75bf7d8774-dxxjn  0/1    Pending            0         1s
airflow-redis-master-0               0/1    ContainerCreating  0         1s
airflow-scheduler-8696d66bcf-bwm2s   0/1    ContainerCreating  0         1s
airflow-web-84797489f5-8wzsm         0/1    ContainerCreating  0         1s
airflow-worker-0                     0/1    Pending            0         0s

==> v1/Secret
NAME                TYPE    DATA  AGE
airflow-postgresql  Opaque  1     2s
airflow-redis       Opaque  1     2s

==> v1/Service
NAME                    TYPE       CLUSTER-IP   EXTERNAL-IP  PORT(S)   AGE
airflow-flower          ClusterIP  10.0.7.168   <none>       5555/TCP  1s
airflow-postgresql      ClusterIP  10.0.8.62    <none>       5432/TCP  2s
airflow-redis-headless  ClusterIP  None         <none>       6379/TCP  1s
airflow-redis-master    ClusterIP  10.0.8.5     <none>       6379/TCP  1s
airflow-web             ClusterIP  10.0.10.176  <none>       8080/TCP  1s
airflow-worker          ClusterIP  None         <none>       8793/TCP  1s

==> v1/ServiceAccount
NAME     SECRETS  AGE
airflow  1        2s

==> v1/StatefulSet
NAME            READY  AGE
airflow-worker  0/1    1s

==> v1beta1/Deployment
NAME                READY  UP-TO-DATE  AVAILABLE  AGE
airflow-postgresql  0/1    1           0          1s

==> v1beta1/PodDisruptionBudget
NAME         MIN AVAILABLE  MAX UNAVAILABLE  ALLOWED DISRUPTIONS  AGE
airflow-pdb  N/A            1                0                    2s

==> v1beta1/Role
NAME     AGE
airflow  2s

==> v1beta1/RoleBinding
NAME     AGE
airflow  2s

==> v1beta2/StatefulSet
NAME                  READY  AGE
airflow-redis-master  0/1    1s


NOTES:
Congratulations. You have just deployed Apache Airflow
   export POD_NAME=$(kubectl get pods --namespace airflow -l "component=web,app=airflow" -o jsonpath="{.items[0].metadata.name}")
   echo http://127.0.0.1:8080
   kubectl port-forward --namespace airflow $POD_NAME 8080:8080

2. Open Airflow in your web browser

【讨论】:

  • 我执行了步骤 1、2、3,但 dags_folder 仍然没有更改,并且 Airflow Web UI 是空的,没有 dag(因为它指向错误的 dag 文件夹)。这就是我在 values.yaml extraVolumeMounts: - name: synchronised-dags mountPath: /usr/local/airflow/dags extraVolumes: - name: synchronised-dags emptyDir: {} dags: path: /Users/e192270/airflow/dags 中所做的任何建议
  • 我按照上述步骤操作,但它也对我不起作用。
猜你喜欢
  • 2021-05-31
  • 2022-01-06
  • 1970-01-01
  • 2021-09-14
  • 2021-11-11
  • 2019-05-11
  • 1970-01-01
  • 1970-01-01
  • 2020-06-30
相关资源
最近更新 更多