如何在 Airflow 中允许访问 Compute Engine 虚拟机(Google Cloud Composer)

How to allow an access to a Compute Engine VM in Airflow (Google Cloud Composer )

我尝试使用 Airflow 中的 BashOperator 运行 以这种模式 ssh user@host "my bash command" 执行 bash 命令。这在本地有效,因为我在目标机器上有我的 public 密钥。

但我想在 Google Cloud Composer 中 运行 这个命令,也就是 Airflow + Google Kubernetes Engine。我了解到 Airflow 的核心程序是 运行ning in 3 pods named according to this pattern airflow-worker-xxxxxxxxx-yyyyy

一个天真的解决方案是为每个 pod 创建一个 ssh 密钥,并将它的 public 密钥添加到 Compute Engine 中的目标机器。该解决方案一直有效到今天,不知何故我的 3 pods 发生了变化,所以我的 ssh 密钥不见了。这绝对不是最好的解决方案。

我有 2 个问题:

Pods 重启不是 Composer 特有的。 I would say this is more related to kubernetes itself:

Pods aren’t intended to be treated as durable entities.

所以一般来说 pods 可以出于不同的原因重新启动,所以你不应该依赖你对它们所做的任何更改。

How can I resolve my issue ?

考虑到 Cloud Composer 会创建一个 Cloud Storage 存储桶并将其链接到您的环境,您可以解决此问题。您可以从您的任何工作人员访问此存储桶的不同文件夹。因此,您可以将密钥(您只能使用一对密钥)存储在 "gs://bucket-name/data" 中,您可以通过映射目录“/home/airflow/gcs/data”访问它。 Docs here