Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pelajari cara membuat dan menggunakan label di layanan dan revisi penayangan Knative Anda.
Label adalah key-value pair yang diterapkan ke layanan dan revisi. Saat
Anda menetapkan label pada layanan penayangan Knative, revisi baru dengan
label ini akan dibuat untuk layanan ini; label tidak diterapkan ke revisi
lama.
Label untuk penayangan Knative adalah
label resource Kubernetes,
dan tidak di-propagate ke Google Cloud. Untuk mempelajari lebih lanjut cara menggunakan label untuk menganalisis penggunaan resource cluster, lihat Memahami penggunaan resource cluster.
Setiap perubahan konfigurasi akan
menghasilkan revisi baru. Revisi selanjutnya juga akan otomatis mendapatkan
setelan konfigurasi ini, kecuali jika Anda melakukan pembaruan eksplisit untuk mengubahnya.
Anda dapat menetapkan atau mengubah label menggunakan konsol Google Cloud , Google Cloud CLI, atau file YAML saat men-deploy layanan baru atau mengupdate layanan yang ada dan men-deploy revisi:
KEY1=VALUE1,KEY2=VALUE2 dengan daftar pasangan nama dan nilai yang dipisahkan koma untuk setiap label.
Tentukan nama label untuk setiap
KEY dan nilai untuk
VALUE.
Cara menentukan beberapa parameter.
Opsi parameter perintah
Untuk menentukan beberapa kumpulan pasangan nilai kunci, Anda
dapat menentukan beberapa parameter untuk keterbacaan. Contoh:
IMAGE_URL dengan referensi ke image container,
misalnya, gcr.io/cloudrun/hello.
SERVICE dengan nama layanan Anda.
KEY1=VALUE1,KEY2=VALUE2 dengan daftar pasangan nama dan nilai yang dipisahkan koma untuk setiap label.
Tentukan nama label untuk setiap
KEY dan nilai untuk
VALUE.
Cara menentukan beberapa parameter.
Opsi parameter perintah
Untuk menentukan beberapa kumpulan pasangan nilai kunci, Anda
dapat menentukan beberapa parameter untuk keterbacaan. Contoh:
Anda dapat mendownload konfigurasi layanan yang ada ke dalam
file YAML dengan perintah gcloud run services describe menggunakan
tanda --format=export.
Kemudian, Anda dapat mengubah file YAML tersebut dan men-deploy
perubahan tersebut dengan perintah gcloud run services replace.
Anda harus memastikan bahwa Anda hanya mengubah atribut yang ditentukan.
Download konfigurasi layanan Anda ke dalam file bernama
service.yaml di ruang kerja lokal:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-30 UTC."],[],[],null,["# Using labels\n\nLearn how to create and use labels in your Knative serving services and\nrevisions.\n\nLabels are key/value pairs that are applied to the service and revisions. When\nyou set a label on a Knative serving service, a new revision with\nthis label is created for this service; the label is not applied to older\nrevisions.\n\nLabels for Knative serving are\n[Kubernetes resource labels](/kubernetes-engine/docs/how-to/cluster-usage-metering),\nand are not propagated to Google Cloud. To learn more about using\nlabels to analyze cluster resource usage, see\n[Understanding cluster resource usage](/kubernetes-engine/docs/how-to/cluster-usage-metering).\n\nLabels usage rules\n------------------\n\nOnly [valid Kubernetes labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) are allowed to be used on Knative serving.\n\nSetting or modifying labels\n---------------------------\n\nAny configuration change leads to the\ncreation of a new revision. Subsequent revisions will also automatically get\nthis configuration setting unless you make explicit updates to change it.\n\nYou can set or modify labels using the Google Cloud console, the\nGoogle Cloud CLI, or a YAML file when you deploy a new\n[service](/kubernetes-engine/enterprise/knative-serving/docs/deploying#service) or update an existing service and\ndeploy a [revision](/kubernetes-engine/enterprise/knative-serving/docs/deploying#revision): \n\n### Console\n\n1. Go to Knative serving in the Google Cloud console:\n\n[Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n\n1. Check the checkbox at the left of the service you are setting the label\n on.\n\n2. Make sure the *Info Panel* at the far right is toggled on\n (**Show Info Panel**).\n\n3. Click **Labels** to display the labels pane.\n\n4. To edit an existing label key value, locate the label and change the\n *Value* as desired.\n\n5. To set a new label on the service, click **Add Label** and supply the key\n and the value.\n\n6. Click **Save**\n\n### Command line\n\nYou can use the Google Cloud CLI to set labels\nfor new services or to update existing services:\n\n\u003cbr /\u003e\n\n- For existing services, update labels by running the\n [`gcloud run services update`](/sdk/gcloud/reference/run/services/update)\n command with one of the following parameters:\n\n - [`--set-labels`](/sdk/gcloud/reference/run/services/update#--set-labels)\n - [`--update-labels`](/sdk/gcloud/reference/run/services/update#--update-labels)\n - [`--remove-labels`](/sdk/gcloud/reference/run/services/update#--remove-labels)\n - [`--clear-labels`](/sdk/gcloud/reference/run/services/update#--clear-labels)\n\n Example: \n\n ```bash\n gcloud run services update SERVICE --update-labels KEY1=VALUE1,KEY2=VALUE2\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eKEY1=VALUE1,KEY2=VALUE2\u003c/var\u003e with a comma separated list of name and value pairs for each label. Specify the label name for each \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e and the value for \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e. [How to specify multiple parameters](#command-line). \n\n ### Command parameter options\n\n To specify several sets of key-value pairs, you can specify multiple parameters for readability. Example: \n\n ```bash\n [...]\n --set-labels \"KEY=VALUE1\" \\\n --set-labels \"KEY=VALUE2\" \\\n --set-labels \"KEY=VALUE3\"\n ``` \n OK\n- For new services, set labels by running the\n `gcloud run deploy` command with the\n [`--set-labels`](/sdk/gcloud/reference/run/deploy#--set-labels)\n parameter:\n\n ```bash\n gcloud run deploy SERVICE --image=IMAGE_URL --set-labels KEY1=VALUE1,KEY2=VALUE2\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for example, `gcr.io/cloudrun/hello`.\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eKEY1=VALUE1,KEY2=VALUE2\u003c/var\u003e with a comma separated list of name and value pairs for each label. Specify the label name for each \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e and the value for \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e. [How to specify multiple parameters](#command-line). \n\n ### Command parameter options\n\n To specify several sets of key-value pairs, you can specify multiple parameters for readability. Example: \n\n ```bash\n [...]\n --set-labels \"KEY=VALUE1\" \\\n --set-labels \"KEY=VALUE2\" \\\n --set-labels \"KEY=VALUE3\"\n ``` \n OK\n\n### YAML\n\n| **Caution:** Deploying configuration changes using YAML files replaces the configuration of your existing services. Since a YAML file completely overwrites all configurations, you should avoid using multiple methods to modify your services. For example, do not use YAML files in conjunction with the Google Cloud console or `gcloud` commands.\n\nYou can download the configuration of an existing service into a\nYAML file with the `gcloud run services describe` command by using the\n[`--format=export`](/sdk/gcloud/reference/run/services/describe) flag.\nYou can then modify that YAML file and deploy\nthose changes with the `gcloud run services replace` command.\nYou must ensure that you modify only the specified attributes.\n\n1. Download the configuration of your service into a file named\n `service.yaml` on local workspace:\n\n ```bash\n gcloud run services describe SERVICE --format export \u003e service.yaml\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your\n Knative serving service.\n2. In your local file, update the `labels` attribute:\n\n ```yaml\n apiVersion: serving.knative.dev/v1\n kind: Service\n metadata:\n name: SERVICE\n labels:\n LABEL: '\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e'\n ```\n\n Replace\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your Knative serving service\n - \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e with the name of the label\n - \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with the desired value\n3. Replace the service with its new configuration using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```\n\nListing services by label\n-------------------------\n\nYou can list services by label using a [Google Cloud CLI filter](/sdk/gcloud/reference/topic/filters):\n\n\u003cbr /\u003e\n\n```bash\n gcloud run services list --filter metadata.labels.LABEL=VALUE\n \n```\n\n\u003cbr /\u003e\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e with the name of the label\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with the value to include in your filtered list\n\nDeleting a label\n----------------\n\nYou can use the console or the command line delete labels. \n\n### Console\n\n1. Go to Knative serving in the Google Cloud console:\n\n[Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n\n1. Check the checkbox at the left of the service you are deleting the label\n from.\n\n2. Make sure the *Info Panel* at the far right is toggled on\n (**Show Info Panel**).\n\n3. Click **Labels** to display the labels pane.\n\n4. Locate the label you want to delete.\n\n5. Hover your cursor to the right of the *Value* textbox for the label to\n display the trash icon, and click the trash icon.\n\n6. Click **Save**\n\n### Command line\n\nTo clear all labels from a service:\n\n\u003cbr /\u003e\n\n```bash\ngcloud run services update SERVICE --clear-labels\n```\n\n\u003cbr /\u003e\n\nTo delete specific labels from a service, supply a comma delimited list of\nkeys:\n\n\u003cbr /\u003e\n\n```bash\ngcloud run services update SERVICE --remove-labels LABEL\n```\n\n\u003cbr /\u003e\n\nReplace\n\n- \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with name of your Knative serving service\n- \u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e with the name of your label"]]