Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Cloud Run-Labels sind Schlüssel/Wert-Paare, die auf Cloud Run-Jobs angewendet werden. Auf dieser Seite wird beschrieben, wie Sie Labels für Ihre Cloud Run-Jobs festlegen, ändern und löschen.
Mögliche Anwendungsfälle:
Verwendung für die Kostenzuordnung und Abrechnungsaufschlüsselung.
Ressourcen identifizieren, die von einzelnen Teams oder Kostenstellen verwendet werden.
Bereitstellungsumgebungen unterscheiden (Produktion, Staging, QA oder Test).
Inhaber, Labels für Status identifizieren.
Logs in Logging filtern.
Nutzungsregeln für Labels
Die folgende Regel gilt für die Verwendung von Labels, die für einen Cloud Run-Job festgelegt sind:
Bitten Sie Ihren Administrator, Ihnen die folgenden IAM-Rollen zu gewähren, um die zum Konfigurieren von Cloud Run-Jobs erforderlichen Berechtigungen zu erhalten:
Wenn Sie einen neuen Job erstellen, überspringen Sie diesen Schritt.
Wenn Sie einen vorhandenen Job aktualisieren, laden Sie die zugehörige YAML-Konfiguration herunter:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-12-05 (UTC)."],[],[],null,["# Configure labels for jobs\n\nCloud Run labels are key-value pairs that are applied to\nCloud Run jobs. This page shows how to set, modify, and\ndelete labels on your Cloud Run jobs.\n\nPossible uses include:\n\n- Cost allocation and billing breakdowns.\n- Identify resources used by individual teams or cost centers.\n- Distinguish deployment environments (prod, staging, qa, or test).\n- Identify owners and state labels.\n- Filter logs in Logging.\n\nLabels usage rules\n------------------\n\nThe following rule applies to the use of labels set on a\nCloud Run job:\n\nOnly [valid Google Cloud labels](/resource-manager/docs/creating-managing-labels) can be used on Cloud Run.\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to configure Cloud Run jobs,\n\nask your administrator to grant you the\nfollowing IAM roles:\n\n- [Cloud Run Developer](/iam/docs/roles-permissions/run#run.developer) (`roles/run.developer`) on the Cloud Run job\n- [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity\n\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run job interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/jobs/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nSet or modify labels\n--------------------\n\nYou can use Google Cloud CLI, YAML, or Terraform to set a label on a\nCloud Run job. \n\n### gcloud\n\n1. To [set a label](/sdk/gcloud/reference/run/jobs/create) on a new job:\n\n ```bash\n gcloud run jobs create JOB_NAME --image IMAGE_URL --labels KEY=VALUE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e with the name of your job.\n - \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e with the name of your label key.\n - \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with the value for the key.\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e: a reference to the [container image](/run/docs/building/containers)---for example, `us-docker.pkg.dev/cloudrun/container/job:latest`.\n2. To set a label on an existing job:\n\n ```bash\n gcloud run jobs update JOB_NAME --labels KEY=VALUE\n ```\n3. To create more than one label, supply a comma delimited list of key/value pairs.\n\n ```bash\n gcloud run jobs update JOB_NAME --labels KEY1=VALUE1,KEY2=VALUE2 \n ```\n\n### YAML\n\n1. If you are creating a new job, skip this step.\n If you are updating an existing job, download its [YAML configuration](/run/docs/reference/yaml/v1#job):\n\n ```bash\n gcloud run jobs describe JOB_NAME --format export \u003e job.yaml\n ```\n2. Update the `labels` attributes in two places:\n\n ```yaml\n apiVersion: run.googleapis.com/v1\n kind: Job\n metadata:\n labels:\n LABEL: VALUE\n spec:\n template:\n metadata:\n labels:\n LABEL: VALUE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e with the name of the label.\n - \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with the chosen value.\n\n You can also specify more configuration such as environment variables or\n memory limits.\n3. Update the existing job configuration:\n\n ```bash\n gcloud run jobs replace job.yaml\n ```\n\n### Terraform\n\n\u003cbr /\u003e\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\nAdd the following to a [`google_cloud_run_v2_job`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_job) resource in your Terraform configuration: \n\n\u003cbr /\u003e\n\n resource \"google_cloud_run_v2_job\" \"default\" {\n name = \"\u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e\"\n location = \"\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\"\n\n template {\n template {\n containers {\n image = \"us-docker.pkg.dev/cloudrun/container/job\"\n }\n }\n labels = {\n \"\u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e\":\"\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\"\n }\n }\n labels = {\n \"\u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e\":\"\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\"\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name of your Cloud Run job.\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the Google Cloud region. For example, `europe-west1`.\n- \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e: the name of the label.\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: the chosen value.\n\nList jobs by label\n------------------\n\nYou can list jobs by label using a\n[Google Cloud CLI filter](/sdk/gcloud/reference/topic/filters):\n\n\u003cbr /\u003e\n\n```bash\n gcloud run jobs list --filter metadata.labels.LABEL=VALUE\n \n```\n\n\u003cbr /\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e: the name of the label\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: the value to include in your filtered list\n\nDelete a label on a job\n-----------------------\n\nTo clear all labels from a job: \n\n```bash\ngcloud run jobs update JOB --clear-labels\n```\n\n\u003cbr /\u003e\n\nTo delete specific labels from a service, supply a comma delimited list of keys: \n\n```bash\ngcloud run jobs update JOB --remove-labels LABEL\n```\n\n\u003cbr /\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eJOB\u003c/var\u003e: the name of your Cloud Run job\n- \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e: the name of your label"]]