Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Découvrez comment créer et utiliser des libellés dans vos services et révisions Knative serving.
Les libellés sont des paires clé/valeur appliquées au service et aux révisions. Lorsque vous définissez un libellé sur un service Knative serving, une révision portant ce libellé est créée pour ce service. Le libellé n'est pas appliqué aux anciennes versions.
Toute modification de configuration entraîne la création d'une révision. Les révisions ultérieures obtiennent aussi automatiquement le même paramètre de configuration, à moins que vous ne le mettiez explicitement à jour.
Vous pouvez définir ou modifier des libellés à l'aide de la console Google Cloud, de Google Cloud CLI ou d'un fichier YAML lorsque vous déployez un nouveau service, ou mettez à jour un service existant et déployez une révision :
Console
Accédez à Knative serving dans la console Google Cloud :
KEY1=VALUE1,KEY2=VALUE2 par une liste de paires nom/valeur séparées par des virgules pour chaque libellé.
Indiquez le nom du libellé pour chaque KEY et la valeur pour VALUE.
Découvrez comment spécifier plusieurs paramètres.
Options des paramètres de commande
Pour spécifier plusieurs ensembles de paires clé/valeur, vous pouvez spécifier plusieurs paramètres pour plus de lisibilité. Exemple :
IMAGE_URL par une référence à l'image de conteneur, par exemple gcr.io/cloudrun/hello ;
SERVICE par le nom de votre service.
KEY1=VALUE1,KEY2=VALUE2 par une liste de paires nom/valeur séparées par des virgules pour chaque libellé.
Indiquez le nom du libellé pour chaque KEY et la valeur pour VALUE.
Découvrez comment spécifier plusieurs paramètres.
Options des paramètres de commande
Pour spécifier plusieurs ensembles de paires clé/valeur, vous pouvez spécifier plusieurs paramètres pour plus de lisibilité. Exemple :
Vous pouvez télécharger la configuration d'un service existant dans un fichier YAML avec la commande gcloud run services describe à l'aide de l'option --format=export.
Vous pouvez ensuite modifier ce fichier YAML et déployer ces modifications à l'aide de la commande gcloud run services replace.
Veillez à ne modifier que les attributs spécifiés.
Téléchargez la configuration de votre service dans un fichier nommé service.yaml sur l'espace de travail local :
SERVICE par le nom de votre service Knative serving
LABEL par le nom de votre libellé.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2024/11/22 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2024/11/22 (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"]]