【问题标题】:What's the recommended way to stop the current version of app engine using gcloud?使用 gcloud 停止当前版本的应用引擎的推荐方法是什么?
【发布时间】:2018-08-04 12:18:27
【问题描述】:

我想通过运行 bash 脚本来自动启动/停止我们的应用引擎服务。

我知道运行gcloud app versions start/stop 很容易,但我不想手动检查版本号。我想动态地将提供 100% 流量的版本传递给 gcloud 并告诉它停止。

另一方面,我还想告诉 gcloud 启动最近部署的版本。

推荐的方法是什么?

谢谢!

【问题讨论】:

  • 注意gcloud app versions start|stop命令只适用于手动伸缩的服务,而流量切换/拆分适用于动态伸缩的服务。

标签: google-app-engine gcloud


【解决方案1】:

一种方法是在使用gcloud app deploy 部署时使用--stop-previous-version 和/或--promote 选项(如果我正确解释文档,它们应该是默认值,除非您使用@987654330 @和/或--no-promote):

--promote

提升已部署的版本以接收所有流量。覆盖 此命令的默认 app/promote_by_default 属性值 调用。使用--no-promote 禁用。

--stop-previous-version

在部署新版本时停止之前运行的版本 接收所有流量。覆盖默认值 app/stop_previous_version 此命令的属性值 调用。使用--no-stop-previous-version 禁用。

但是,如果您使用的是标准环境和动态扩展,您应该注意,如果以前的版本处理大量流量,则在切换期间可能会出现服务降级/中断(GAE 可能需要一段时间自动缩放器来确定它需要启动多少新版本实例来处理该流量,请参阅Use traffic migration or splitting when switching to a new default version。您可以通过编程方式执行这些操作,请参阅不适用于不支持流量拆分的 flex 环境。

也可能感兴趣:GAE shutdown or restart all the active instances of a service/app

您只能控制默认路由到哪个已部署版本的流量,您不能真正停止到已部署版本的所有流量,始终可以通过@987654324 访问@。

顺便说一句,gcloud 应用版本 [start|stop] 命令仅适用于手动扩展的服务:

只有在您的服务的扩展模块已经 设置为手动。

【讨论】:

  • 谢谢丹!但是,我不想部署新版本。我想关闭/打开现有服务,我认为这些命令只能使用 gcloud app deploy
  • 确实想要部署并切换到新版本,但 --stop-previous-version 标志明确指出它不适用于自动缩放的版本。这很烦人,因为据我所知,应用引擎从不 关闭我的自动缩放实例,即使它们没有收到流量;大概我可以将最小实例设置为允许缩放为零,但我不希望 current 版本(我想要几个实例)。
【解决方案2】:

一种方法是使用gcloud 的键和标志:projections--format--filters。要直接从终端阅读更多内容,请使用gcloud topic,例如:

gcloud topic projections

要查看可用的字段/属性,请使用--format=flattened,例如:

gcloud app services list --format=flattened

为了简单起见,除了gcloud,我将把所有东西都放在外面。

for SERVICE in $(gcloud app services list --format='table[no-heading](id)'); do
    echo "for service $SERVICE :"

    RECENT=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE" | tail -n1)

    echo 'y' | gcloud app versions start $RECENT

    VERSIONS=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" | tr '\n' ' ')

    echo 'y' | gcloud app versions stop $VERSIONS
done

'table[no-heading](service)' 输出一个没有标题的表格,它被设置在括号中,以及一个带有服务 ID 的列,它被设置在括号中。

--filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" 将仅显示来自指定服务的正在服务的版本,RECENT 指定的版本除外。

此外,如果您想使用日期进行过滤:

gcloud app versions list --format='table(id, version.servingStatus, version.createTime.date(format="%s"))' --filter="service=default" --sort-by="~version.createTime"

version.createTime.date(format="%s") 是一个function dateversion.createTime.date 转换为自纪元以来的秒数。

%s 来自strftime(3) 并以更易于理解和比较的 Epoch 格式返回日期。

--sort-by="~version.createTime"按创建日期排序,因为~按降序排列。

【讨论】:

  • 完美!感谢您的帮助:)
猜你喜欢
  • 2021-09-04
  • 1970-01-01
  • 1970-01-01
  • 2011-01-20
  • 2012-10-12
  • 2017-05-27
  • 2016-10-12
  • 2010-09-11
  • 1970-01-01
相关资源
最近更新 更多