Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos a criação de um serviço e a visualização de informações sobre ele.
Os serviços são os principais recursos do Knative serving.
criar um serviço
Para criar um novo serviço e a revisão dele,
implante uma imagem de contêiner nele pela primeira vez. Consulte
Como implantar um novo serviço para saber mais sobre
como criar serviços.
Como ver a lista de serviços no projeto
É possível visualizar uma lista dos serviços disponíveis no projeto usando o
console do Google Cloud ou a Google Cloud CLI:
Console
Para ver a lista de serviços, realize as etapas a seguir:
Acesse o Knative serving no console do Google Cloud:
Examine a lista de serviços exibidos para seu projeto:
Linha de comando
Para listar os serviços no projeto, use este código:
gcloud run services list
É possível filtrar essa lista por propriedades da definição de serviço, como um
rótulo atribuído.
Como copiar um serviço
É possível fazer uma cópia de um serviço atual usando o console do Google Cloud ou o YAML.
Você pode alterar o que quiser na cópia, incluindo o nome e a região.
Console
Para copiar um serviço:
Acesse o Knative serving no console do Google Cloud:
Selecione o serviço a ser copiado na lista exibida de serviços do seu
projeto:
Clique em Copiar.
Na página de cópia do serviço, defina ou altere os valores que você quer alterar,
como região etc. Se você mantiver a mesma região, forneça um
novo nome para o serviço.
Clique em Criar para fazer uma cópia e implantá-la usando o novo nome de
serviço.
YAML
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:
Se você estiver implantando a cópia no mesmo cluster do Kubernetes, substitua
SERVICE pelo nome que você quer usar para a cópia. Se você estiver
implantando a cópia em outro cluster do Kubernetes, será possível usar o
mesmo nome.
Certifique-se de que o valor de REVISION-NAME comece com o nome do
serviço (SERVICE). Por exemplo, se o novo nome de serviço for
mynewfoo, o nome da revisão precisará estar no formato mynewfoo-whatever.
Se preferir, exclua o valor inteiro, e um novo nome de revisão será criado
automaticamente.
Copie o serviço usando o seguinte comando:
gcloudrunservicesreplaceservice.yaml
Use a sinalização --region
para implantar a cópia em uma região diferente.
Como ver mais detalhes sobre um serviço
A seguir, saiba como ver mais detalhes sobre um serviço.
Console
Para ver os detalhes de um serviço, realize as etapas a seguir:
Acesse o Knative serving no console do Google Cloud:
Clique no serviço pretendido na lista exibida para abrir a visualização de detalhes do serviço:
Observe as guias REVISÕES, REGISTROS e DETALHES. A guia "Revisões" mostra a lista de revisões, a guia "Registros" mostra os registros de serviços e a guia "Detalhes" mostra as configurações atuais de autenticação ou conectividade.
Linha de comando
Para ver detalhes sobre um serviço, realize as etapas a seguir:
gcloudrunservicesdescribeSERVICE
Substitua SERVICE pelo nome do serviço.
É possível usar a sinalização --format para formatar a saída. Por exemplo, como YAML:
gcloudrunservicesdescribeSERVICE--formatyaml
É possível usar --format export para exportar como YAML sem rótulos
ou status gerados automaticamente:
Substitua [SERVICE] pelo nome do serviço que você está atualizando.
É possível omitir inteiramente esse parâmetro, mas será solicitado o nome do serviço, se você omiti-lo.
Substitua [OPTION] por internal ou external.
Como excluir serviços atuais
A exclusão de um serviço exclui todos os recursos relacionados a ele, incluindo todas as revisões desse serviço, independentemente de estarem veiculando tráfego ou não.
Ao excluir um serviço, as imagens do contêiner usadas pelas revisões excluídas não são
excluídas automaticamente do Container Registry. Para excluir imagens de contêiner do
Container Registry, consulte Como excluir imagens.
Observe que a exclusão de um serviço é permanente: não há como desfazer ou restaurar.
No entanto, se após a exclusão de um serviço você implantar um novo serviço com o mesmo
nome no mesmo cluster, ele terá o mesmo URL do endpoint.
Console
Para excluir um serviço, realize as etapas a seguir:
Acesse o Knative serving no console do Google Cloud:
[[["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-09-05 UTC."],[],[],null,["# Managing services\n\nThis page describes creating a service and viewing information about a service.\nServices are the main resources of Knative serving.\n\nCreating a service\n------------------\n\nYou create a new service and its [revision](/kubernetes-engine/enterprise/knative-serving/docs/managing/revisions) by\ndeploying a container image to it for the first time. See\n[Deploying a new service](/kubernetes-engine/enterprise/knative-serving/docs/deploying#service) to learn more about\ncreating services.\n\nViewing the list of services in your project\n--------------------------------------------\n\nYou can view a list of the available services in your project using\nGoogle Cloud console or the Google Cloud CLI: \n\n### Console\n\nTo view the services list:\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Examine the displayed list of services for your project:\n\n### Command line\n\nTo list the services in your project: \n\n gcloud run services list\n\nYou can filter this list by properties of the service definition, such as an\n[assigned label](/kubernetes-engine/enterprise/knative-serving/docs/configuring/labels#label-listing).\n\nCopying a service\n-----------------\n\nYou can make a copy of an existing service using Google Cloud console or YAML.\nYou can change anything you want in the copy, including name and region. \n\n### Console\n\nTo copy a service:\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Select the service to copy from the displayed list of services for your\n project:\n\n 1. Click **Copy**.\n\n 2. In the service copy page, set or change any values you want to change,\n such as region, etc. If you are keeping the same region, you must provide a\n new name for the service.\n\n 3. Click **Create** to make a copy and deploy it using the new service\n name.\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. Make any desired configuration changes to the service as described in the\n various [configuration pages](/kubernetes-engine/enterprise/knative-serving/docs/how-to#configure).\n\n apiVersion: serving.knative.dev/v1\n kind: Service\n metadata:\n annotations:\n ...\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eSERVICE\u003c/span\u003e\u003c/var\u003e\n ...\n spec:\n template:\n metadata:\n annotations:\n ...\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eREVISION-NAME\u003c/span\u003e\u003c/var\u003e\n\n - If you are deploying the copy to the same Kubernetes cluster, replace\n \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name you want to use for the copy. If you are\n deploying the copy to a different Kubernetes cluster, you can use the\n same name.\n\n - Make sure the value for \u003cvar translate=\"no\"\u003eREVISION-NAME\u003c/var\u003e starts with the service\n name (\u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e). For example, if the new service name is\n `mynewfoo`, then the revision name must be in the format `mynewfoo-whatever`.\n Optionally delete the value altogether and a new revision name is created\n automatically.\n\n3. Copy the service using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```\n\n Use the [`--region`](/sdk/gcloud/reference/run/services/replace#--region)\n flag to deploy the copy to a different region.\n\nViewing more details about a service\n------------------------------------\n\nTo see more details about a service, \n\n### Console\n\nTo view a service's details:\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Click on the desired service in the displayed list of services for your\n project to open the service details view:\n\n3. Note the **REVISIONS** , **LOGS** and **DETAILS** tabs. The revisions tab\n shows the list of revisions, the logs tab shows the [service logs](/kubernetes-engine/enterprise/knative-serving/docs/logging),\n and the details tab shows the current\n [authentication](/kubernetes-engine/enterprise/knative-serving/docs/deploying#service) or\n [connectivity](#connectivity) settings.\n\n### Command line\n\nTo view details about a service: \n\n```bash\ngcloud run services describe SERVICE\n```\nReplace \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of the service.\n\n\u003cbr /\u003e\n\nYou can use the [`--format` flag](/sdk/gcloud/reference#--format) to format\nthe output. For example as YAML: \n\n```bash\ngcloud run services describe SERVICE --format yaml\n```\n\nYou can use `--format export` to export as YAML without automatically\ngenerated labels or status: \n\n```bash\ngcloud run services describe SERVICE --format export\n```\n\nYou can also use the [`--format` flag](/sdk/gcloud/reference#--format) to get\nthe URL of the service: \n\n```bash\ngcloud run services describe SERVICE --format='value(status.url)'\n```\n\n\u003cbr /\u003e\n\nFor details about the revisions of a service, see\n[Managing Revisions](/kubernetes-engine/enterprise/knative-serving/docs/managing/revisions).\n\nChanging service connectivity settings\n--------------------------------------\n\nA Knative serving service can have either of two connection options:\n\n- *external*, which allows external access to your service\n\n- *internal* which restricts access only to other services in your cluster.\n\nYou can use the console or the Google Cloud CLI to change the settings. \n\n### Console\n\nTo change service connectivity settings:\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Click on the desired service in the displayed list of services for your\n project to open the service details view.\n\n3. Click the **Triggers** tab.\n\n4. Select the desired setting and click **Save**.\n\n### Command line\n\nTo change service connectivity settings, update the service with the desired\nconnectivity setting: \n\n gcloud run services update [SERVICE] --connectivity=[OPTION]\n\n- Replace `[SERVICE]` with the name of the service you are updating.\n You can omit this parameter entirely, but you will be prompted for the\n service name if you omit it.\n\n- Replace `[OPTION]` with `internal` or `external`.\n\nDeleting existing services\n--------------------------\n\nDeleting a service deletes all resources related to this service, including all\nrevisions of this service whether they are serving traffic or not.\n\nWhen deleting a service, the container images used by the deleted revisions are not\ndeleted automatically from Container Registry. To delete container images from\nContainer Registry see [Deleting images](/container-registry/docs/managing#deleting_images).\n\nNote that deleting a service is permanent: there is no undo or restore.\nHowever, if after deleting a service, you deploy a new service with the same\nname in the same cluster, it will have the same endpoint URL. \n\n### Console\n\nTo delete a service:\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Locate the service you want to delete in the services list, and click\n its checkbox to select it.\n\n3. Click **DELETE**. This deletes all revisions of the service.\n\n### Command line\n\nTo delete a service, use the command: \n\n gcloud run services delete [SERVICE]\n\nReplace `[SERVICE]` with the name of your service."]]