Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Scopri come creare e utilizzare le etichette nelle revisioni e nei servizi Knative serving.
Le etichette sono coppie chiave/valore applicate al servizio e alle revisioni. Quando imposta un'etichetta su un servizio Knative serving, viene creata una nuova revisione con questa etichetta per il servizio. L'etichetta non viene applicata alle revisioni precedenti.
Qualsiasi modifica alla configurazione comporta la
creazione di una nuova revisione. Anche le revisioni successive acquisiranno automaticamente questa impostazione di configurazione, a meno che non apporti aggiornamenti espliciti per modificarla.
Puoi impostare o modificare le etichette utilizzando la Google Cloud console, Google Cloud CLI o un file YAML quando esegui il deployment di un nuovo
servizio o aggiorni un servizio esistente e
esegui il deployment di una revisione:
Console
Vai alla pubblicazione Knative nella Google Cloud console:
KEY1=VALUE1,KEY2=VALUE2 con un elenco di coppie di nome e valore per ogni etichetta separato da virgole.
Specifica il nome dell'etichetta per ogni
KEY e il valore per
VALUE.
Come specificare più parametri.
Opzioni del parametro del comando
Per specificare più insiemi di coppie chiave-valore, puoi indicare più parametri per la leggibilità. Esempio:
IMAGE_URL con un riferimento all'immagine del container, ad esempio gcr.io/cloudrun/hello.
SERVICE con il nome del servizio.
KEY1=VALUE1,KEY2=VALUE2 con un elenco di coppie di nome e valore per ogni etichetta separato da virgole.
Specifica il nome dell'etichetta per ogni
KEY e il valore per
VALUE.
Come specificare più parametri.
Opzioni del parametro del comando
Per specificare più insiemi di coppie chiave-valore, puoi indicare più parametri per la leggibilità. Esempio:
Puoi scaricare la configurazione di un servizio esistente in un
file YAML con il comando gcloud run services describe utilizzando il
--format=export flag.
Puoi quindi modificare il file YAML e implementare queste modifiche con il comando gcloud run services replace.
Devi assicurarti di modificare solo gli attributi specificati.
Scarica la configurazione del servizio in un file denominato
service.yaml nello spazio di lavoro locale:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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"]]