如何检查最新的Cloud Run修订版是否准备就绪

问题描述 投票:2回答:2

我使用Cloud Run已有一段时间了,整个用户体验简直太棒了!

当前,我正在使用Cloud Build部署容器映像,将映像推送到GCR,然后创建新的Cloud Run修订版。现在,我想调用一个脚本,以在将最新修订版成功部署到Cloud Run之后从CDN清除缓存,但是$ gcloud run deploy命令无法告诉您流量是否开始指向最新修订版。

我可以订阅任何命令或事件以确保没有流量指向旧版本,以便我可以安全地清除所有缓存吗?

google-cloud-platform cdn google-cloud-pubsub google-cloud-build google-cloud-run
2个回答
0
投票

您可以使用gcloud run revisions list获取所有修订的列表:

$ gcloud run revisions list --service helloworld

   REVISION          ACTIVE  SERVICE     DEPLOYED                 DEPLOYED BY
✔  helloworld-00009  yes     helloworld  2019-08-17 02:09:01 UTC  [email protected]
✔  helloworld-00008          helloworld  2019-08-17 01:59:38 UTC  [email protected]
✔  helloworld-00007          helloworld  2019-08-13 22:58:18 UTC  [email protected]
✔  helloworld-00006          helloworld  2019-08-13 22:51:18 UTC  [email protected]
✔  helloworld-00005          helloworld  2019-08-13 22:46:14 UTC  [email protected]
✔  helloworld-00004          helloworld  2019-08-13 22:41:44 UTC  [email protected]
✔  helloworld-00003          helloworld  2019-08-13 22:39:16 UTC  [email protected]
✔  helloworld-00002          helloworld  2019-08-13 22:36:06 UTC  [email protected]
✔  helloworld-00001          helloworld  2019-08-13 22:30:03 UTC  [email protected]

您还可以使用gcloud run revisions describe获取有关特定修订的详细信息,该修订将包含status字段。例如,一个有效的修订版:

$ gcloud run revisions describe helloworld-00009
...
status:
  conditions:
  - lastTransitionTime: '2019-08-17T02:09:07.871Z'
    status: 'True'
    type: Ready
  - lastTransitionTime: '2019-08-17T02:09:14.027Z'
    status: 'True'
    type: Active
  - lastTransitionTime: '2019-08-17T02:09:07.871Z'
    status: 'True'
    type: ContainerHealthy
  - lastTransitionTime: '2019-08-17T02:09:05.483Z'
    status: 'True'
    type: ResourcesAvailable

以及无效的修订:

$ gcloud run revisions describe helloworld-00008
...
status:
  conditions:
  - lastTransitionTime: '2019-08-17T01:59:45.713Z'
    status: 'True'
    type: Ready
  - lastTransitionTime: '2019-08-17T02:39:46.975Z'
    message: Revision retired.
    reason: Retired
    status: 'False'
    type: Active
  - lastTransitionTime: '2019-08-17T01:59:45.713Z'
    status: 'True'
    type: ContainerHealthy
  - lastTransitionTime: '2019-08-17T01:59:43.142Z'
    status: 'True'
    type: ResourcesAvailable

您将特别想检查type: Active条件。

这也可以通过Cloud Run REST API来使用:https://cloud.google.com/run/docs/reference/rest/v1/namespaces.revisions


0
投票

默认情况下,流量会路由到最新版本。您可以在日志中看到它。

Deploying container to Cloud Run service [SERVICE_NAME] in project [YOUR_PROJECT] region [YOUR_REGION]
✓ Deploying... Done.                                                           
  ✓ Creating Revision...
  ✓ Routing traffic...
Done.
Service [SERVICE_NAME] revision [SERVICE_NAME-00012-yic] has been deployed and is serving 100 percent of traffic at https://SERVICE_NAME-vqg64v3fcq-uc.a.run.app

如果要确定,可以显式调用update traffic命令

gcloud run services update-traffic --platform=managed --region=YOUR_REGION --to-latest YOUR_SERVICE
© www.soinside.com 2019 - 2024. All rights reserved.