<p>First time creating a pipeline in Google Cloud Platform.</p>

<p>I have been following their guide, and the last step I want to set the build container into Kubernetes cluster.</p>

<p>This is my yaml file that is failling in the last step.</p>

<pre><code>steps:

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

  # This step runs the unit tests on the app
  - name: 'docker.io/library/python:3.7'
    id: Test
    entrypoint: /bin/sh
    args:
      - -c
      - 'pip install -r requirements.txt &amp;&amp; python -m pytest app/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/scrapper-config', 'scrappercontroller=gcr.io/abiding-robot-255320/scrappercontroller']
    env:
      - 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
      - 'CLOUDSDK_CONTAINER_CLUSTER=n1scrapping'
</code></pre>

<p>I have been using GCP guideline </p>

<pre><code>- name: 'gcr.io/cloud-builders/kubectl'
  args: ['set', 'image', 'deployment/myimage', 'frontend=gcr.io/myproject/myimage']
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=us-east1-b'
  - 'CLOUDSDK_CONTAINER_CLUSTER=node-example-cluster'
</code></pre>

<p>But I dont know what do I have to replace in the last argument. <code>frontend=gcr.io/myproject/myimage</code> in my case.</p>

<p>Also my intention is to replace the container that is running on kubernetes, if this help identifying any issues.</p>

<p>Thanks for any help!</p>

Patrick Vibild
<p>I'm going to guess from the title you're seeing a message like this in your CloudBuild logs:</p>

<pre class="lang-sh prettyprint-override"><code>+ kubectl set image deployment/scrapper-config scrappercontroller=gcr.io/abiding-robot-255320/scrappercontroller
error: unable to find container named "scrappercontroller"
</code></pre>

<blockquote>
  <p>I dont know what do I have to replace in the last argument. <code>frontend=gcr.io/myproject/myimage</code> in my case.</p>
</blockquote>

<p>The meaning of this argument is <code>&lt;container_name&gt;=&lt;image_ref&gt;</code>.<br>
You're setting this value to <code>scrappercontroller=gcr.io/abiding-robot-255320/scrappercontroller</code>.<br>
That means: "set the image for the 'scrappercontroller' container in my Pods to this image from GCR".</p>

<p>You can learn more about this by running <code>kubectl set image --help</code>:</p>

<pre class="lang-sh prettyprint-override"><code>Update existing container image(s) of resources.

 Possible resources include (case insensitive):

  pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), replicaset (rs)

Examples:
  # Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
  kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1

  # Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
  kubectl set image deployments,rc nginx=nginx:1.9.1 --all

  # Update image of all containers of daemonset abc to 'nginx:1.9.1'
  kubectl set image daemonset abc *=nginx:1.9.1

  # Print result (in yaml format) of updating nginx container image from local file, without hitting the server
  kubectl set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml
</code></pre>

<p>You're working with a <code>Deployment</code> object.
<code>Deployments</code> create <code>Pods</code> using their <code>spec.template</code>.</p>

<p><code>Pods</code> can have multiple <code>containers</code>, and each one will have a name.<br>
This command will show you your container names for the Pods in your Deployment:</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get --output=wide deploy/scrapper-config
</code></pre>

<p>Here's an example of a <code>Deployment</code> that creates <code>Pods</code> with two containers: "myapp" and "cool-sidecar". (See the <code>CONTAINERS</code> column.)</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get --output=wide deploy/myapp
NAME    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS           IMAGES        SELECTOR
myapp   1/1     1            0           10m   myapp,cool-sidecar   nginx,nginx   run=myapp
</code></pre>

<p>You can use that container name in your final argument:</p>

<pre><code>'my-container-name=gcr.io/abiding-robot-255320/scrappercontroller'
</code></pre>

<p>You can also just use a wildcard(<code>*</code>) if your Pods only have a single container each:</p>

<pre><code>'*=gcr.io/abiding-robot-255320/scrappercontroller'
</code></pre>

<p>Hopefully that helps 👍</p>
