Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Aprenda a criar e usar rótulos nos serviços e revisões do Knative
serving.
Rótulos são pares de chave-valor aplicados ao serviço e às revisões. Quando
você define um rótulo em um serviço do Knative serving, uma nova revisão com
esse rótulo é criada para esse serviço. O rótulo não é aplicado a revisões
mais antigas.
Qualquer mudança na configuração leva à
criação de uma nova revisão. As próximas revisões também recebem automaticamente essa configuração, a menos que você faça atualizações explícitas para alterá-la.
É possível definir ou modificar rótulos usando o console do Cloud, a
Google Cloud CLI ou um arquivo YAML ao implantar um novo
serviço ou atualizar um serviço atual e
implantar uma revisão:
Console
Acesse o Knative serving no console do Google Cloud:
KEY1=VALUE1,KEY2=VALUE2 com uma lista separada
por vírgula de pares de nome e valor para cada rótulo.
Especifique o nome do rótulo para cada KEY e o valor para VALUE.
Como especificar vários parâmetros:
Opções de parâmetros de comando
Para especificar vários conjuntos de pares de chave-valor, é
possível especificar vários parâmetros de legibilidade. Exemplo:
IMAGE_URL por uma referência à imagem de contêiner. Por
exemplo, gcr.io/cloudrun/hello;
SERVICE pelo nome do serviço;
KEY1=VALUE1,KEY2=VALUE2 com uma lista separada
por vírgula de pares de nome e valor para cada rótulo.
Especifique o nome do rótulo para cada KEY e o valor para VALUE.
Como especificar vários parâmetros:
Opções de parâmetros de comando
Para especificar vários conjuntos de pares de chave-valor, é
possível especificar vários parâmetros de legibilidade. Exemplo:
Faça o download da configuração de um serviço existente para um
arquivo YAML com o comando gcloud run services describe usando a
sinalização --format=export.
Em seguida, modifique o arquivo YAML e implante
essas alterações com o comando gcloud run services replace.
Modifique apenas os atributos especificados.
Faça o download da configuração do serviço em um arquivo chamado
service.yaml no espaço de trabalho local:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2024-11-26 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"]]