Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
.
Les règles de sécurité de l'organisation, les règles de conformité réglementaires et d'autres considérations peuvent vous inciter à "faire tourner" vos clusters Dataproc à intervalles réguliers en les supprimant, puis en les recréant selon une planification.
Lors de la rotation des clusters, de nouveaux clusters peuvent être provisionnés avec les dernières versions d'image Dataproc tout en conservant les paramètres de configuration des clusters remplacés.
Cette page explique comment configurer les clusters que vous prévoyez de faire pivoter ("clusters pivotés"), comment y envoyer des jobs, puis comment faire pivoter les clusters selon vos besoins.
Rotation des clusters d'image personnalisée : vous pouvez appliquer des personnalisations précédentes ou nouvelles à une image de base Dataproc précédente ou nouvelle lorsque vous recréez le cluster d'image personnalisée.
Configurer des clusters pivotés
Pour configurer des clusters permutés, créez des noms de cluster uniques avec un suffixe d'horodatage afin de distinguer les anciens clusters des nouveaux. Ensuite, ajoutez des libellés aux clusters pour indiquer si un cluster fait partie d'un pool de clusters permutés et s'il reçoit activement de nouvelles demandes de job. Cet exemple utilise les libellés cluster-pool et cluster-state=active à ces fins, mais vous pouvez utiliser vos propres noms de libellés.
cluster-pool-name : nom du pool de clusters associé à un ou plusieurs clusters. Ce nom est utilisé dans le nom du cluster et avec le libellé cluster-pool associé au cluster pour identifier le cluster comme faisant partie du pool.
Créez le cluster. Vous pouvez ajouter des arguments et utiliser différents libellés.
Les exemples suivants du Google Cloud CLI et de graphe orienté acyclique (DAG) Apache Airflow envoient une tâche Apache Pig à un cluster. Les libellés de cluster permettent d'envoyer le job à un cluster actif dans un pool de clusters.
gcloud
Envoyez une tâche Apache Pig située dans Cloud Storage. Sélectionnez le cluster à l'aide des libellés.
Envoyez un job Apache Pig situé dans Cloud Storage à l'aide d'Airflow.
Sélectionnez le cluster à l'aide des libellés.
from airflow import DAG
from airflow.providers.google.cloud.operators.dataproc import DataprocSubmitJobOperator
from datetime import datetime
# Declare variables
project_id= # e.g: my-project
region="us-central1"
dag_id='pig_wordcount'
cluster_labels={"cluster-pool":${CLUSTER_POOL},
"cluster-state":"active"}
wordcount_script="gs://bucket-name/scripts/wordcount.pig"
# Define DAG
dag = DAG(
dag_id,
schedule_interval=None,
start_date=datetime(2023, 8, 16),
catchup=False
)
PIG_JOB = {
"reference": {"project_id": project_id},
"placement": {"cluster_labels": cluster_labels},
"pig_job": {"query_file_uri": wordcount_script},
}
wordcount_task = DataprocSubmitJobOperator(
task_id='wordcount',
region=region,
project_id=project_id,
job=PIG_JOB,
dag=dag
)
Faire pivoter des clusters
Mettez à jour les libellés de cluster associés aux clusters que vous supprimez. Cet exemple utilise le libellé cluster-state=pendingfordeletion pour indiquer que le cluster ne reçoit pas de nouvelles tâches et qu'il est en cours de remplacement, mais vous pouvez utiliser votre propre libellé à cet effet.
Une fois l'étiquette du cluster mise à jour, le cluster ne reçoit plus de tâches, car elles ne sont envoyées qu'aux clusters d'un pool de clusters avec des étiquettes active (voir Envoyer des tâches à des clusters).
Supprimez les clusters que vous remplacez une fois qu'ils ont terminé d'exécuter les jobs.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eDataproc clusters can be rotated at regular intervals to adhere to security policies and compliance rules, enabling the provisioning of new clusters with updated image versions while retaining configurations.\u003c/p\u003e\n"],["\u003cp\u003eRotated clusters are set up by assigning unique, timestamp-suffixed names and attaching labels like \u003ccode\u003ecluster-pool\u003c/code\u003e and \u003ccode\u003ecluster-state=active\u003c/code\u003e to distinguish and identify them within a pool.\u003c/p\u003e\n"],["\u003cp\u003eJobs can be submitted to active clusters within a cluster pool by using cluster labels to ensure that the job is directed to a cluster that is currently accepting new submissions.\u003c/p\u003e\n"],["\u003cp\u003eClusters are rotated by updating their labels to indicate they are no longer active, for example, by changing \u003ccode\u003ecluster-state=active\u003c/code\u003e to \u003ccode\u003ecluster-state=pendingfordeletion\u003c/code\u003e, which prevents them from receiving new jobs.\u003c/p\u003e\n"],["\u003cp\u003eClusters marked as ready for deletion can be removed after they have completed their current jobs, which can be automated using a monitoring script.\u003c/p\u003e\n"]]],[],null,[".\n\nOrganization security policies, regulatory compliance rules, and other\nconsiderations can prompt you to \"rotate\" your Dataproc clusters\nat regular intervals by deleting, then recreating clusters on a schedule.\nAs part of cluster rotation, new clusters can be provisioned with the latest\nDataproc image versions while retaining the configuration settings\nof the replaced clusters.\n\nThis page shows you how to set up clusters that you plan to rotate (\"rotated\nclusters\"), submit jobs to them, and then rotate the clusters as needed.\n\n[Custom image](/dataproc/docs/guides/dataproc-images) cluster rotation:\nYou can apply previous or new customizations to a previous or new\nDataproc base image when recreating the custom image cluster.\n\nSet up rotated clusters\n\nTo set up rotated clusters, create unique, timestamp-suffixed cluster names\nto distinguish previous from new clusters, and then attach labels to clusters\nthat indicate if a cluster is part of a rotated cluster pool and actively\nreceiving new job submissions. This example uses `cluster-pool` and\n`cluster-state=active` labels for these purposes, but you can use\nyour own label names.\n\n1. Set environment variables:\n\n ```\n PROJECT=project ID \\\n REGION=/compute/docs/regions-zones#available \\\n CLUSTER_POOL=cluster-pool-name \\\n CLUSTER_NAME=$CLUSTER_POOL-$(date '+%Y%m%d%H%M') \\\n BUCKET=Cloud Storage bucket-name\n ```\n\n \u003cbr /\u003e\n\n Notes:\n - \u003cvar translate=\"no\"\u003ecluster-pool-name\u003c/var\u003e: The name of the cluster pool associated with one or more clusters. This name is used in the cluster name and with the `cluster-pool` label attached to the cluster to identify the cluster as part of the pool.\n2. Create the cluster. You can add arguments and use different labels.\n\n ```\n gcloud dataproc clusters create ${CLUSTER_NAME} \\\n --project=${PROJECT_ID} \\\n --region=${REGION} \\\n --bucket=${BUCKET} \\\n --labels=\"cluster-pool=${CLUSTER_POOL},cluster-state=active\"\n ```\n\nSubmit jobs to clusters\n\nThe following Google Cloud CLI and\n[Apache Airflow directed acyclic graph (DAG)](/composer/docs/how-to/using/writing-dags)\nexamples submit an Apache Pig job to a cluster. Cluster labels are\nused to submit the job to an active cluster within a cluster pool. \n\ngcloud\n\nSubmit an Apache Pig job located in Cloud Storage. Pick the cluster using labels.\n\n\u003cbr /\u003e\n\n```\ngcloud dataproc jobs submit pig \\\n --region=${REGION} \\\n --file=gs://${BUCKET}/scripts/script.pig \\\n --cluster-labels=\"cluster-pool=${CLUSTER_POOL},cluster-state=active\"\n \n```\n\n\u003cbr /\u003e\n\nAirflow\n\nSubmit an Apache Pig job located in Cloud Storage using Airflow.\nPick the cluster using labels. \n\n```\nfrom airflow import DAG\nfrom airflow.providers.google.cloud.operators.dataproc import DataprocSubmitJobOperator\nfrom datetime import datetime\n\n# Declare variables\nproject_id= # e.g: my-project\nregion=\"us-central1\"\ndag_id='pig_wordcount'\ncluster_labels={\"cluster-pool\":${CLUSTER_POOL},\n \"cluster-state\":\"active\"}\nwordcount_script=\"gs://bucket-name/scripts/wordcount.pig\"\n\n# Define DAG\n\ndag = DAG(\n dag_id,\n schedule_interval=None,\n start_date=datetime(2023, 8, 16),\n catchup=False\n)\n\nPIG_JOB = {\n \"reference\": {\"project_id\": project_id},\n \"placement\": {\"cluster_labels\": cluster_labels},\n \"pig_job\": {\"query_file_uri\": wordcount_script},\n}\n\nwordcount_task = DataprocSubmitJobOperator(\n task_id='wordcount',\n region=region,\n project_id=project_id,\n job=PIG_JOB,\n dag=dag\n)\n```\n\n\u003cbr /\u003e\n\nRotate clusters\n\n1. Update the cluster labels attached to the clusters you are rotating out. This\n examples uses the `cluster-state=pendingfordeletion` label to signify that\n the cluster is not receiving new job submissions and is being rotated out,\n but you can use your own label for this purpose.\n\n ```\n gcloud dataproc clusters update ${CLUSTER_NAME} \\\n --region=${REGION} \\\n --update-labels=\"cluster-state=pendingfordeletion\"\n ```\n\n \u003cbr /\u003e\n\n After the cluster label is updated, the cluster does not receive new jobs\n since jobs are submitted to clusters within a cluster pool\n with `active` labels only (see\n [Submit jobs to clusters](#submit_jobs_to_clusters)).\n2. Delete clusters you are rotating out after they finish running jobs.\n\n | **Note:** You can automate this step with a monitoring script that fetches clusters with the `cluster-state=pendingfordeletion` label (or other label you added with the previous command), checks that no jobs are running on the cluster, and then deletes the cluster."]]