gpt4 book ai didi

kubernetes - Google云平台使用Kubernetes创建管道并替换相同的容器

转载 作者:行者123 更新时间:2023-12-02 12:02:53 26 4
gpt4 key购买 nike

我正在努力尝试用Google Cloud Platform的容器注册中的容器替换现有容器。

这是我的cloudbuild.yaml文件。

脚步:

  # This steps clone the repository into GCP
- name: gcr.io/cloud-builders/git
args: ['clone', 'https:///user/:password@github.com/PatrickVibild/scrappercontroller']

# This step runs the unit tests on the src
- name: 'docker.io/library/python:3.7'
id: Test
entrypoint: /bin/sh
args:
- -c
- 'pip install -r requirements.txt && python -m pytest src/tests/**'

#This step creates a container and leave it on CloudBuilds repository.
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/abiding-robot-255320/scrappercontroller', '.']

#Adds the container to Google container registry as an artefact
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/abiding-robot-255320/scrappercontroller']

#Uses the container and replaces the existing one in Kubernetes
- name: 'gcr.io/cloud-builders/kubectl'
args: ['set', 'image', 'deployment/scrappercontroller', 'scrappercontroller-sha256=gcr.io/abiding-robot-255320/scrappercontroller:latest']
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=scrapper-admin'

我在构建项目时没有任何问题,并且所有步骤都变得绿色,在最后一步中可能会缺少我,但是我找不到用新版本代码替换集群中容器的方法。

我可以使用GUI在我的现有集群中手动创建一个新的工作负载,并从容器注册表中选择一个容器,但是从那里用我的云新版本替换该工作负载容器的步骤失败了。

最佳答案

这是一个常见的陷阱。根据documentation:

Note: A Deployment’s rollout is triggered if and only if the Deployment’s Pod template (that is, .spec.template) is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout.



您的问题来自图像的标记,它没有改变: :latest已部署,您要求部署 :latest。图像名称没有更改,没有展示。

要更改此设置,建议您使用 substitution variables,尤其是 COMMIT_SHASHORT_SHA。您不能在文档中这样做:

only available for triggered builds



这意味着仅在自动触发构建而不是手动触发构建时填充此变量。

对于手动运行,您必须指定自己的变量,如下所示
gcloud builds submit --substitutions=COMMIT_SHA=<what you want>

然后像这样更新您的构建脚本:
  # This steps clone the repository into GCP
- name: gcr.io/cloud-builders/git
args: ['clone', 'https:///user/:password@github.com/PatrickVibild/scrappercontroller']

# This step runs the unit tests on the src
- name: 'docker.io/library/python:3.7'
id: Test
entrypoint: /bin/sh
args:
- -c
- 'pip install -r requirements.txt && python -m pytest src/tests/**'

#This step creates a container and leave it on CloudBuilds repository.
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/abiding-robot-255320/scrappercontroller:$COMMIT_SHA', '.']

#Adds the container to Google container registry as an artefact
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/abiding-robot-255320/scrappercontroller:$COMMIT_SHA']

#Uses the container and replaces the existing one in Kubernetes
- name: 'gcr.io/cloud-builders/kubectl'
args: ['set', 'image', 'deployment/scrappercontroller', 'scrappercontroller-sha256=gcr.io/abiding-robot-255320/scrappercontroller:COMMIT_SHA']
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=scrapper-admin'

在部署期间,您应该看到以下行:
Step #2: Running: kubectl set image deployment.apps/test-deploy go111=gcr.io/<projectID>/postip:<what you want>
Step #2: deployment.apps/test-deploy image updated

如果您看不到它,则表示您的部署未考虑在内。

关于kubernetes - Google云平台使用Kubernetes创建管道并替换相同的容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531740/

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