我正在尝试使用 DataprocCreateClusterOperator 在 Airflow DAG 内的 GCP 项目中创建 Dataproc 集群。我正在使用 ClusterGenerator 生成集群的配置。但是,我想指定通常使用 gcloud CLI 指定的
--public-ip-address
(请参阅:https://cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create#--public-ip-地址),但它似乎不是 ClusterGenerator 的可能输入(来源:https://github.com/apache/airflow/blob/main/airflow/providers/google/cloud/operators/dataproc.py# L122)?
当使用 ClusterGenerator 或仅使用通用 API 格式时,如何调整
--public-ip-address
?
我的代码目前是这样的:
from airflow import models
from airflow.providers.google.cloud.operators.dataproc import (
ClusterGenerator,
DataprocCreateClusterOperator,
)
from google.api_core.retry import Retry
DATAPROC_CLUSTER_CONFIG = ClusterGenerator(
project_id=GCP_PROJECT,
region=GCP_REGION,
master_machine_type="n2-standard-4",
master_disk_type="pd-standard",
master_disk_size=500,
worker_machine_type="n2-standard-4",
worker_disk_type="pd-standard",
worker_disk_size=500,
num_workers=2,
image_version="2.2-ubuntu22",
storage_bucket=DATAPROC_BUCKET,
properties={
"dataproc:pip.packages": "sentence-transformers==3.0.1,pydantic==2.8.2"
},
internal_ip_only=False,
enable_component_gateway=True,
).make()
with models.DAG() as dag:
create_dataproc_cluster = DataprocCreateClusterOperator(
task_id="create_dataproc_cluster",
project_id=GCP_PROJECT,
cluster_config=DATAPROC_CLUSTER_CONFIG,
region=GCP_REGION,
cluster_name=DATAPROC_CLUSTER_NAME,
retry=Retry(maximum=100.0, initial=10.0, multiplier=1.0),
)
最后,我发现 ClusterGenerator 类不起作用 - 通过阅读此问题:https://github.com/apache/airflow/issues/17089
通过添加以下内容,您将在 Dataproc 集群上获得相同的设置(如
--public-ip-address
):internal_ip_only=False 和 enable_component_gateway=True。然而在我之前的代码中,ClusterGenerator 不起作用。
您需要自己指定配置,例如:
DATAPROC_CLUSTER_CONFIG = {
"config_bucket": DATAPROC_BUCKET,
"gce_cluster_config": {
"internal_ip_only": False,
},
"software_config": {
"properties": {
"dataproc:pip.packages": "sentence-transformers==3.0.1,pydantic==2.8.2",
}
},
"endpoint_config": {
"enable_http_port_access": True
}
}