Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何检查最新的Cloud Run修订版是否已准备就绪_Google Cloud Platform_Cdn_Google Cloud Pubsub_Google Cloud Build_Google Cloud Run - Fatal编程技术网

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

Google cloud platform 如何检查最新的Cloud Run修订版是否已准备就绪,google-cloud-platform,cdn,google-cloud-pubsub,google-cloud-build,google-cloud-run,Google Cloud Platform,Cdn,Google Cloud Pubsub,Google Cloud Build,Google Cloud Run,我已经使用Cloud Run一段时间了,整个用户体验简直太棒了 目前,我正在使用Cloud Build部署容器映像,将映像推送到GCR,然后创建一个新的Cloud Run修订版。 现在我想调用一个脚本,在最新版本成功部署到Cloud Run后清除CDN中的缓存,但是$gcloud Run deploy命令无法告诉您流量是否开始指向最新版本 是否有任何命令或事件可供我订阅,以确保没有流量指向旧版本,以便我可以安全地清除所有缓存?您可以使用gcloud run revisions list获取所有版

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

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


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

您可以使用
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@email.com
✔  helloworld-00008          helloworld  2019-08-17 01:59:38 UTC  email@email.com
✔  helloworld-00007          helloworld  2019-08-13 22:58:18 UTC  email@email.com
✔  helloworld-00006          helloworld  2019-08-13 22:51:18 UTC  email@email.com
✔  helloworld-00005          helloworld  2019-08-13 22:46:14 UTC  email@email.com
✔  helloworld-00004          helloworld  2019-08-13 22:41:44 UTC  email@email.com
✔  helloworld-00003          helloworld  2019-08-13 22:39:16 UTC  email@email.com
✔  helloworld-00002          helloworld  2019-08-13 22:36:06 UTC  email@email.com
✔  helloworld-00001          helloworld  2019-08-13 22:30:03 UTC  email@email.com
您还可以使用
gcloud run revisions description
获取特定修订的详细信息,该修订将包含一个
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
和一个非活动版本:

$ 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
您特别需要检查
类型:Active
条件


这些都可以通过云运行RESTAPI获得:

默认情况下,流量路由到最新版本。你可以在日志中看到这一点

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
如果您想确定,可以显式调用updatetraffic命令

gcloud run services update-traffic --platform=managed --region=YOUR_REGION --to-latest YOUR_SERVICE

@Dustin的回答是正确的,但是“状态”消息是
Route
配置的间接结果,因为这些消息是单独更新的(您可能会看到它们之间有几秒钟的延迟)。如果您不介意的话,状态消息仍然可以告诉您修订版已停止轮换

要直接使用API对象回答此特定问题(我的重点):

是否有任何我可以订阅的命令或事件确保没有流量指向旧版本

您需要查看API上的
Route
对象。这是一个Knative API(在云运行时可用),但它没有
gcloud
命令:

例如,假设您在云运行服务上划分了50%-50%的流量。当您这样做时,您将找到您的
服务
对象(您可以在云控制台上看到)→ 云端→ YAML选项卡)具有以下
spec.traffic
字段:

spec:
  traffic:
  - revisionName: hello-00002-mob
    percent: 50
  - revisionName: hello-00001-vat
    percent: 50
这是“期望的配置”,但实际上可能无法最终反映状态。更改此字段将转到并更新
路由
对象–该对象决定如何分割流量

要查看封面下的
Route
对象(很遗憾,我必须在这里使用curl,因为没有
gcloud
命令用于此:)

此命令将显示输出:

  "spec": {
    "traffic": [
      {
        "revisionName": "hello-00002-mob",
        "percent": 50
      },
      {
        "revisionName": "hello-00001-vat",
        "percent": 50
      }
    ]
  },
(您可能会注意到它与服务的
spec.traffic
——因为它是从那里复制的)可以明确地告诉您当前哪些修订版为该特定服务的流量提供服务。

谢谢Ahmet!>这是“期望的配置”,但实际上可能无法确切反映状态是,这正是我在运行
$gcloud run services description
命令时担心的问题。(就像我为我的k8s服务所做的那样)检查
Route
对象可能是解决此问题的完美方案:)