Google cloud platform creating a pipeline with Kubernetes and replacing the same container

前端 未结 1 1622
猫巷女王i
猫巷女王i 2021-01-25 12:31

I am struggling trying to replace an existing container with a container from my container-register from Google Cloud Platform.

This is my cloudbuild.yaml file.

相关标签:
1条回答
  • 2021-01-25 13:13

    It's a common pitfall. According with the 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.

    Your issue come from the tag of your image doesn't change: the :latest is deployed and you ask for deploying :latest. No image name change, no rollout.

    For changing this, I propose you to use substitution variables, especially COMMIT_SHA or SHORT_SHA. You can not this in the documentation:

    only available for triggered builds

    This means that this variable is only populated when the build is automatically triggered and not manually.

    For manual run, you have to specify your own variable, like this

    gcloud builds submit --substitutions=COMMIT_SHA=<what you want>
    

    And update your build script like this:

      # 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'
    

    And during the deployment, you should see this line:

    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
    

    If you don't see it, this mean that your rollout has not take into account.

    0 讨论(0)
提交回复
热议问题