gpt4 book ai didi

google-cloud-platform - 如何自动更新 Google Cloud 托管实例组

转载 作者:行者123 更新时间:2023-12-04 17:08:24 26 4
gpt4 key购买 nike

我使用带有实例模板(容器注册表)的谷歌云实例组来管理许多实例。但是我的 MIG 有一些问题。

我在实例模板中将容器注册表路径设置为 gcr.io/prok/server

我希望 MIG 在我将新版本的 docker 镜像推送到容器注册表时自动更新,但事实并非如此。 MIG 不会自动更新。

许多关于 MIG 的文章说要为更新创建新实例模板 (v1->v2) 并将 MIG 中的实例模板更改为新版本模板...但我希望 MIG 自动更新而不创建新实例模板。

我该怎么做?

最佳答案

可以将整个过程自动化,但需要使用 Pub/Sub notifications 触发新模板的创建:

When changes are made to your Container Registry repository, such as when images are pushed, tagged, or deleted, you can receive notifications using Pub/Sub.

Pub/Sub publishes messages about your repository to named resources called topics. These messages are received by applications subscribed to Pub/Sub topics. Subscriber applications send notifications when your repository's state changes.

当您更新图像或将新图像上传到 Artifact Registry 时,将生成一条发布-订阅消息,此时唯一要做的就是检查是否有新消息,例如gcloud(这只是一个例子):

gcloud pubsub subscriptions pull sub1
DATA: {"action":"INSERT","digest":"gcr.io/project-name/my-repo/busybox@sha256:34efe68cca33507682b1673c851700ec66839ecf94d19b928176e20d20e02413","tag":"gcr.io/project-name/my-repo/busybox:latest"}
MESSAGE_ID: 3401997393579
ORDERING_KEY:
ATTRIBUTES:
DELIVERY_ATTEMPT:
ACK_ID: UAYWLF1GSFE3GAoRRAIAE8CKF15MFc8QV98BT4NGXJ9

这当然必须使用专用 VM 来完成,该 VM 将为您的更新进行检查和创建新模板;你又可以create one使用 gcloud:gcloud compute instance-templates create-with-container INSTANCE_TEMPLATE_NAME --container-image=CONTAINER_IMAGE

模板准备就绪后,您可以运行 rolling update :

gcloud compute instance-groups managed rolling-action start-update INSTANCE_GROUP_NAME \
--version=template=INSTANCE_TEMPLATE \
--type=opportunistic|proactive \
[--zone=ZONE | --region=REGION]

我还找到了this answer描述过程,但添加了 Cloud Scheduler - 您可能会发现它非常有用。

关于google-cloud-platform - 如何自动更新 Google Cloud 托管实例组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70015877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com