Using labels

This page shows how to set, modify, and delete labels on your Cloud Run service and revisions. For Cloud Run, labels are key/value pairs that are applied to the service and revisions. When you set a label on a Cloud Run service, a new revision with this label is created for this service; the label is not applied to older revisions.

For Cloud Run (fully managed), labels are propagated to GCP and so be used directly to filter billing, logs, metrics, and so forth. Possible uses of this include:

  • Use for cost allocation and billing breakdowns.
  • Identify resources used by individual teams or cost centers
  • Distinguish deployment environments (prod, staging, qa, or test)
  • Identify owners, state labels.
  • Monitor resource groups via Logging or Monitoring, which use labels accessible in the resource metadata

For Cloud Run for Anthos on Google Cloud, labels are Kubernetes resource labels, and are not propagated to GCP.

Labels usage rules

The following rules apply to the use of labels set on a Cloud Run service:

Setting or modifying labels

You can use the console or the command line to set or modify labels.

Console

Using the console, you can set or modify a label on a service any time after you create the service:

  1. Go to Cloud Run

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

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

  4. Click Labels to display the labels pane.

  5. To edit an existing label key value, locate the label and change the Value as desired.

  6. To set a new label on the service, click Add Label and supply the key and the value.

  7. Click Save

    Set label

Command line

You can update labels for a service using the command:

gcloud beta run services update SERVICE --update-labels KEY=VALUE

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

Replace

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

You can also set labels during deployment:

gcloud beta run deploy SERVICE --image IMAGE --labels KEY=VALUE

To create more than one label during deployment, supply a comma delimited list of key/value pairs.

Deleting a label

You can use the console or the command line delete labels.

Console

  1. Go to Cloud Run

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

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

  4. Click Labels to display the labels pane.

  5. Locate the label you want to delete.

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

  7. Click Save

Command line

To clear all labels from a service:

gcloud beta run services update SERVICE --clear-labels

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

gcloud beta run services update SERVICE --remove-labels KEY

Replace

  • SERVICE with name of your Cloud Run service
  • KEY with the name of your label key
本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Cloud Run Documentation