谷歌云平台用Kubernetes创建管道并替换相同的容器

谷歌云平台用Kubernetes创建管道并替换相同的容器,kubernetes,google-cloud-platform,google-kubernetes-engine,Kubernetes,Google Cloud Platform,Google Kubernetes Engine,我正在努力用Google云平台容器注册中的容器替换现有容器 这是我的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 th

我正在努力用Google云平台容器注册中的容器替换现有容器

这是我的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在现有集群内手动创建一个新的工作负载,并从容器注册表中选择一个容器,但是从这里开始,用云中的新版本替换该工作负载容器的步骤失败了。

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

注意:当且仅当展开的Pod模板(即,.spec.template)更改时(例如,如果模板的标签或容器图像更新),才会触发展开的卷展栏。其他更新(如缩放展开)不会触发卷展栏

您的问题来自映像的标记,但没有更改:部署了:latest,您要求部署:latest。没有图像名称更改,没有卷展栏

为了改变这一点,我建议您使用,尤其是COMMIT_-SHA或SHORT_-SHA。您无法在文档中找到此选项:

仅适用于触发的生成

这意味着只有在生成自动触发而非手动触发时,才会填充此变量

对于手动运行,您必须指定自己的变量,如下所示

gcloud builds submit --substitutions=COMMIT_SHA=<what you want>
在部署过程中,您应该看到这一行:

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

如果您没有看到它,这意味着您的卷展没有考虑到它。

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

注意:当且仅当展开的Pod模板(即,.spec.template)更改时(例如,如果模板的标签或容器图像更新),才会触发展开的卷展栏。其他更新(如缩放展开)不会触发卷展栏

您的问题来自映像的标记,但没有更改:部署了:latest,您要求部署:latest。没有图像名称更改,没有卷展栏

为了改变这一点,我建议您使用,尤其是COMMIT_-SHA或SHORT_-SHA。您无法在文档中找到此选项:

仅适用于触发的生成

这意味着只有在生成自动触发而非手动触发时,才会填充此变量

对于手动运行,您必须指定自己的变量,如下所示

gcloud builds submit --substitutions=COMMIT_SHA=<what you want>
在部署过程中,您应该看到这一行:

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
如果您没有看到它,这意味着您的卷展栏没有考虑它