Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Os rótulos do Cloud Run são pares de chave-valor aplicados a
jobs do Cloud Run. Nesta página, mostramos como definir, modificar e excluir rótulos dos jobs do Cloud Run.
Os possíveis usos incluem:
Usar para alocação de custos e detalhamentos de faturamento
Identificar recursos usados por equipes ou centros de custo individuais.
Diferenciar ambientes de implantação (produção, preparo, controle de qualidade ou teste).
Identificar os proprietários e os rótulos de estado
Filtrar registros no Logging.
Regras de uso de rótulos
A regra a seguir se aplica ao uso de rótulos definidos em um
job do Cloud Run:
Se você estiver criando um novo serviço, pule esta etapa.
Se você estiver atualizando um serviço existente, faça o download da configuração YAML correspondente:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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"]]