Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Obtén información para crear y usar etiquetas en los servicios y las revisiones de Knative serving.
Las etiquetas son pares clave-valor que se aplican al servicio y las revisiones. Cuando configuras una etiqueta en un servicio de Knative serving, se crea una nueva revisión con esta etiqueta; la etiqueta no se aplica a revisiones anteriores.
Cualquier cambio en la configuración conlleva la creación de una revisión nueva. Las revisiones posteriores también adoptarán esta configuración de manera automática, a menos que realices actualizaciones explícitas para cambiarla.
Puedes configurar o modificar las etiquetas mediante la consola de Google Cloud, Google Cloud CLI o un archivo YAML cuando implementas un servicio nuevo o actualizas un servicio existente e implementas una revisión:
Console
Ve a Knative serving en la consola de Google Cloud:
KEY1=VALUE1,KEY2=VALUE2 por una lista separada por comas de pares de valores y nombres para cada etiqueta.
Especifica el nombre de la etiqueta de cada KEY y el valor de VALUE.
Cómo especificar varios parámetros.
Opciones de parámetros de comando
A fin de especificar varios conjuntos de pares clave-valor, puedes especificar varios parámetros para facilitar la lectura. Ejemplo:
IMAGE_URL por una referencia a la imagen del contenedor, como gcr.io/cloudrun/hello
SERVICE por el nombre de tu servicio
KEY1=VALUE1,KEY2=VALUE2 por una lista separada por comas de pares de valores y nombres para cada etiqueta.
Especifica el nombre de la etiqueta de cada KEY y el valor de VALUE.
Cómo especificar varios parámetros.
Opciones de parámetros de comando
A fin de especificar varios conjuntos de pares clave-valor, puedes especificar varios parámetros para facilitar la lectura. Ejemplo:
Puedes descargar la configuración de un servicio existente en un archivo YAML con el comando gcloud run services describe mediante la marca --format=export.
Luego, puedes modificar ese archivo YAML e implementar esos cambios con el comando gcloud run services replace.
Debes asegurarte de modificar solo los atributos especificados.
Descarga la configuración del servicio en un archivo llamado service.yaml en el lugar de trabajo local:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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"]]