gpt4 book ai didi

google-cloud-platform - 如何在 cloudbuild.yaml 中为云运行指定自定义 service.yaml?

转载 作者:行者123 更新时间:2023-12-05 04:32:36 24 4
gpt4 key购买 nike

我在 Google 的 Cloud Run 服务上部署了一个 docker 容器。它有一个非常基本的 cloudbuild.yaml 文件,可从 git 推送到主分支触发。

我希望将云跑机器的内存从 512mb 自动增加到 8gb。我知道这可以在 Cloud Run UI 中通过单击“编辑@部署新版本”然后手动选择 8gb 来实现。但我希望自动进行此设置。

您可以通过以下方式从 Cloud Run 获取 .yaml:

gcloud run services describe SERVICE --format export > service.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
annotations:
client.knative.dev/user-image: 'gcr.io/project/service:ebbe555'
run.googleapis.com/ingress: all
run.googleapis.com/ingress-status: all
run.googleapis.com/launch-stage: BETA
labels:
cloud.googleapis.com/location: europe-north1
name: service
namespace: '467851153648'
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/maxScale: '100'
autoscaling.knative.dev/minScale: '1'
client.knative.dev/user-image: 'gcr.io/project/service:ebbe555'
run.googleapis.com/client-name: gcloud
run.googleapis.com/client-version: 378.0.0
run.googleapis.com/execution-environment: gen2
name: faq-engine-00004-vov
spec:
containerConcurrency: 80
containers:
- image: 'gcr.io/project/service:ebbe555'
ports:
- containerPort: 8081
name: http1
resources:
limits:
cpu: 4000m
memory: 8Gi
serviceAccountName: service@project.iam.gserviceaccount.com
timeoutSeconds: 300
traffic:
- latestRevision: true
percent: 100

并且您可以半自动替换当前的 .yaml 为:

gcloud run services 替换 service.yaml

但是,有没有办法让实际的 Cloud Build 在将容器镜像部署到 Cloud Run 步骤中加载自定义 service.yaml

cloudbuild.yaml

timeout: 1800s
substitutions:
_SERVICE_NAME: service
_REGION: europe-north1
images:
- 'gcr.io/${PROJECT_ID}/${_SERVICE_NAME}:${SHORT_SHA}'
options:
machineType: N1_HIGHCPU_32
dynamic_substitutions: true
steps:
- id: Build the container image
name: gcr.io/cloud-builders/docker
args:
- build
- '-t'
- 'gcr.io/${PROJECT_ID}/${_SERVICE_NAME}:${SHORT_SHA}'
- .
- id: Push the container image to Container Registry
name: gcr.io/cloud-builders/docker
args:
- push
- 'gcr.io/${PROJECT_ID}/${_SERVICE_NAME}:${SHORT_SHA}'
- id: Deploy container image to Cloud Run
name: gcr.io/google.com/cloudsdktool/cloud-sdk
entrypoint: gcloud
args:
- run
- deploy
- '${_SERVICE_NAME}'
- '--platform'
- managed
- '--region'
- '${_REGION}'
- '--allow-unauthenticated'
- '--service-account'
- '${_SERVICE_NAME}@${PROJECT_ID}.iam.gserviceaccount.com'
- '--image'
- 'gcr.io/${PROJECT_ID}/${_SERVICE_NAME}:${SHORT_SHA}'

谢谢!

最佳答案

将来自@GuillaumeBlaqueire 和@Lsbister 的评论作为社区 wiki 发布以提高知名度:

要部署 Cloud Run 服务,请使用带有 gcloud run services replace 的 YAML (service.yaml) 或 gcloud 命令 gcloud run deploy。您不能将服务 YAML 与“部署”操作一起使用。

如果您只想使用 deploy 命令将容器的内存设置为 8GBi,您应该为此使用标志 --memory

关于google-cloud-platform - 如何在 cloudbuild.yaml 中为云运行指定自定义 service.yaml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71616877/

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