Configure labels for services

Cloud Run labels are key-value pairs that are applied toCloud Run service and revisions. This page shows how to set, modify, anddelete labels on your Cloud Run service and revisions.Note that when you set a label on a Cloud Runservice, a new revision with this label is created for thisservice; the label is not applied to older revisions.

Possible uses include:

  • Cost allocation and billing breakdowns.
  • Identify resources used by individual teams or cost centers.
  • Distinguish deployment environments (prod, staging, qa, or test).
  • Identify owners and state labels.
  • Filter logs in Logging.

Labels usage rules

The following rule applies to the use of labels set on aCloud Run service:

Onlyvalid Google Cloud labels can be used on Cloud Run.

Required roles

To get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:

If you are deploying aserviceorfunction from source code, youmust also have additional roles granted to you on your project andCloud Build service account.

For a list of IAM roles and permissions that are associated withCloud Run, seeCloud Run IAM rolesandCloud Run IAM permissions.If your Cloud Run service interfaces withGoogle Cloud APIs, such as Cloud Client Libraries, see theservice identity configuration guide.For more information about granting roles, seedeployment permissionsandmanage access.

Set or modify labels

Any configuration change leads to thecreation of a new revision. Subsequent revisions will also automatically getthis configuration setting unless you make explicit updates to change it.

Labels you previously set for your Cloud Run functions using eithergcloud functions commands or the Cloud Functions v2 API propagate to Cloud Run when youdeploy your functions in Cloud Run.

You can set or modify labels using the Google Cloud console, the Google Cloud CLI,or a YAML file when youdeploy a new revision.

Console

  1. In the Google Cloud console, go to the Cloud RunServices page:

    Go to Cloud Run

  2. Check the checkbox at the left of the service you are setting the labelon.

  3. Make sure theInfo Panel at the far right is toggled on(Show Info Panel).

  4. ClickLabels to display the labels pane.

    Set label

  5. To edit an existing label key value, locate the label and change theValue.

  6. To set a new label on the service, clickAdd Label and supply the keyand the value.

  7. ClickSave

gcloud

You can update labels for a service using the command:

gcloudrunservicesupdateSERVICE--update-labelsKEY=VALUE

To update more than one label, supply a comma delimited list of key-value pairs. Note that theupdate-labels command sets a new value for the label key if the label already exists, otherwise it creates a new label.

Replace the following:

  • SERVICE: the name of your Cloud Run service
  • KEY: the name of your label key
  • VALUE: the value for the key

You can also set labels duringdeployment:

gcloudrundeploySERVICE--imageIMAGE--labelsKEY=VALUE

To create more than one label during deployment, supply a comma delimitedlist of key-value pairs.

YAML

  1. If you are creating a new service, skip this step.If you are updating an existing service, download itsYAML configuration:

    gcloudrunservicesdescribeSERVICE--formatexport>service.yaml
  2. Update thelabels attributes in two places:

    apiVersion:serving.knative.dev/v1kind:Servicemetadata:name:SERVICElabels:LABEL:VALUEspec:template:metadata:labels:LABEL:VALUEname:REVISION

    Replace the following:

    • SERVICE: the name of your Cloud Run service
    • LABEL: the name of the label
    • VALUE: the required value
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, itmust meet the following criteria:
      • Starts withSERVICE-
      • Contains only lowercase letters, numbers and-
      • Does not end with a-
      • Does not exceed 63 characters

    metadata.labels sets labels on the service object, whilespec.template.metadata.label sets labels on the created revision.Only labels set on the revision are passed to logs and billing.

  3. Create or update the service using the following command:

    gcloudrunservicesreplaceservice.yaml

Terraform

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Add the following to agoogle_cloud_run_v2_service resource in your Terraform configuration:

resource"google_cloud_run_v2_service""default"{name="cloudrun-service-labels"location="us-central1"deletion_protection=false # set to "true" in productiontemplate{containers{image="us-docker.pkg.dev/cloudrun/container/hello"}    # Labelslabels={foo:"bar"baz:"quux"}}}

The preceding snippet adds two labels,foo (whose value isbar) andbaz(whose value isquux), to your Cloud Run instance.

Adding the labels undertemplate sets the labels for the revision: onlylabels set for the revision are passed to logs and billing. If you add thelabels to a location other than undertemplate, the label is set for theservice not the revision.

Replace the following:

  • name: the name of your service.
  • location: the location used for your service.
  • image: your container image.
  • foo andbaz: your own label names.
  • bar andquux: your own label values.

List services by label

You can list services by label using aGoogle Cloud CLI filter:

gcloudrunserviceslist--filtermetadata.labels.LABEL=VALUE

Replace the following:

  • LABEL: the name of the label
  • VALUE: the value to include in your filtered list

Delete a label on a service

You can use the console or the command line delete labels on a service.

Console

  1. In the Google Cloud console, go to the Cloud RunServices page:

    Go to Cloud Run

  2. Check the checkbox at the left of the service you are deleting the labelfrom.

  3. Make sure theInfo Panel at the far right is toggled on(Show Info Panel).

  4. ClickLabels to display the labels pane.

  5. Locate the label you want to delete.

  6. Hover your cursor to the right of theValue textbox for the label todisplay the trash icon, and click the trash icon.

  7. ClickSave.

gcloud

To clear all labels from a service:

gcloudrunservicesupdateSERVICE--clear-labels

To delete specific labels from a service, supply a comma delimited list ofkeys:

gcloudrunservicesupdateSERVICE--remove-labelsLABEL

Replace the following:

  • SERVICE: the name of your Cloud Run service
  • LABEL: the name of your label

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.