如何通过服务帐户创建 dataproc 集群

how to create dataproc cluster by service account

我对这份文件很困惑enter link description here

Service account requirements and Limitations:
* Service accounts can only be set when a cluster is created.
* You need to create a service account before creating the Cloud Dataproc cluster that will be associated with the service account.
* Once set, the service account used for a cluster cannot be changed.

这是否意味着我无法创建服务帐户,该服务帐户具有创建数据处理集群的作用? 现在,我只能通过我自己的帐户“gcloud auth login”创建一个dataproc集群 但我想通过 setup

从 jenkins 创建 dataproc 集群

gcloud auth activate-service-account --key-file

是的,您可以使用服务帐号创建 Dataproc 集群并提交作业。但是,您提到的 link 涉及 运行 Dataproc 集群,其服务帐户不适用于您的问题。

要使用服务帐户创建 Dataproc:

  1. 创建服务帐户

  2. 分配 Cloud Dataproc Editor 角色

  3. 下载其 json 凭据文件

  4. 配置认证机制:

    4.1 gcloud auth activate-service-account --key-file=JSON_FILE_PATH

    4.2 GOOGLE_APPLICATION_CREDENTIALS=JSON_FILE_PATH

  5. 创建您的 Dataproc 集群

首先您需要创建一个服务帐户,还需要提供对以下角色的访问权限:

  1. Dataproc Worker:根据 [doc][1]

To create a cluster with a user-specified service account, the specified service account must have all permissions granted by the Dataproc Worker role.

2.Dataproc Hub Agent:这将提供访问act as service account权限,否则提供以下错误:

ERROR: (gcloud.beta.dataproc.clusters.create) INVALID_ARGUMENT: User not authorized to act as service account 'service-account@project-id.iam.gserviceaccount.com'. To act as a service account, user must have one of [Owner, Editor, Service Account Actor] roles. See https://cloud.google.com/iam/docs/understanding-service-accounts for additional details.

3.Dataproc 编辑者:此角色将提供创建和删除 dataproc 集群的权限。

激活服务帐户:提供角色访问权限后,下载服务帐户json。通过 gcloud auth active-service-account --key-file=<service-json> 激活新服务帐户。通过 gcloud auth list 检查激活。通过 export GOOGLE_APPLICATION_CREDENTIALS="service-json-full-path"

设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量

现在希望一切准备就绪,可以使用服务帐户创建 dataproc 集群。以下是使用服务帐户创建 dataproc 集群的示例命令:

gcloud auth activate-service-account --key-file=<service-key-file>
export GOOGLE_APPLICATION_CREDENTIALS="<service-key-file>"
gcloud beta dataproc clusters create <CLUSTER-NAME> \
    --region=<REGION> \
    --project=<PROJECT-ID> \
    --service-account=<SERVICE-ACCOUNT-EMAIL> \
    --single-node