[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-26。"],[[["\u003cp\u003eCluster selectors allow workflows to run on existing clusters instead of managed clusters, and the selected cluster is not deleted post-workflow.\u003c/p\u003e\n"],["\u003cp\u003eSelectors use Dataproc user labels to identify eligible clusters within the same region as the workflow, and Dataproc chooses the cluster with the most free YARN memory if multiple clusters match.\u003c/p\u003e\n"],["\u003cp\u003eYou can add a cluster selector to a workflow template using either the Google Cloud CLI or the Dataproc API, with options to set specific cluster labels.\u003c/p\u003e\n"],["\u003cp\u003eAutomatically-applied cluster labels like \u003ccode\u003egoog-dataproc-cluster-name\u003c/code\u003e and \u003ccode\u003egoog-dataproc-cluster-uuid\u003c/code\u003e can be used to point a cluster selector to an existing cluster.\u003c/p\u003e\n"],["\u003cp\u003eClusters with matching labels can be used to create cluster pools, and the workflow template can select a cluster within that pool based on the applied labels.\u003c/p\u003e\n"]]],[],null,["# Use cluster selectors with workflows\n\nAs an alternative to running a workflow on a\n[managed cluster](/dataproc/docs/concepts/workflows/using-workflows#configuring_or_selecting_a_cluster), you can use a\ncluster selector to choose an existing cluster for your workflow. At the\nconclusion of the workflow, the selected cluster is not deleted.\n\nSelectors specify one or more\n[Dataproc user labels](/dataproc/docs/concepts/labels).\nClusters in same\n[region](/compute/docs/regions-zones#available) as the workflow whose labels\nmatch all of the selector labels are eligible to run workflow jobs. If multiple\nclusters match the selector, Dataproc will\nchoose the cluster with the most free YARN memory.\n\nAdd a cluster selector to a template\n------------------------------------\n\nYou can add a cluster selector to a workflow template using the\nGoogle Cloud CLI or the Dataproc API. \n\n### gcloud command\n\n```\ngcloud dataproc workflow-templates set-cluster-selector template-id \\\n --region=region \\\n --cluster-labels=name=value[[,name=value]...]\n```\n\n### REST API\n\nSee [WorkflowTemplatePlacement.ClusterSelector](/dataproc/docs/reference/rest/v1/projects.locations.workflowTemplates#clusterselector). This field is provided as part of a completed [WorkflowTemplate](/dataproc/docs/reference/rest/v1/projects.regions.workflowTemplates#resource-workflowtemplate) submitted with a [workflowTemplates.create](/dataproc/docs/reference/rest/v1/projects.regions.workflowTemplates/create) or [workflowTemplates.update](/dataproc/docs/reference/rest/v1/projects.regions.workflowTemplates/update) request.\n\n### Console\n\nYou can view existing workflow templates and instantiated workflows from\nthe Dataproc\n[**Workflows**](https://console.cloud.google.com/dataproc/workflows/instances) page in Google Cloud console.\n\nUse automatically applied labels\n--------------------------------\n\nYou can point a cluster selector to an existing cluster by using\none of the following [automatically-applied cluster labels](/dataproc/docs/concepts/labels#automatically-applied_labels):\n\n- `goog-dataproc-cluster-name`\n- `goog-dataproc-cluster-uuid`\n\n**Example:** \n\n```\ngcloud dataproc workflow-templates set-cluster-selector template-id \\\n --region=region \\\n --cluster-labels=goog-dataproc-cluster-name=my-cluster\n```\n\n\u003cbr /\u003e\n\nSelect from a cluster pool\n--------------------------\n\nYou can let Dataproc choose a cluster from a pool of clusters.\nThe cluster pools can be defined with labels.\n\n**Example:** \n\n```\ngcloud dataproc clusters create cluster-1 --labels cluster-pool=pool-1 \\\n --region=\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e\ngcloud dataproc clusters create cluster-2 --labels cluster-pool=pool-1 \\\n --region=\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e\ngcloud dataproc clusters create cluster-3 --labels cluster-pool=pool-2 \\\n --region=\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e\n```\n\nAfter cluster creation ... \n\n```\ngcloud dataproc workflow-templates create my-template \\\n --region=\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e\ngcloud dataproc workflow-templates set-cluster-selector my-template \\\n --region=\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e \\\n --cluster-labels=cluster-pool=pool-1\n```\n\nThe workflow will be run on either cluster-1 or cluster-2, but not on cluster-3."]]