<p>I want to deploy an image from cloud run to kubernetes cluster. I have successfully built the docker image in <code>cloudbuild.yaml</code> file. Now the challenge is how to use the image in <code>deploy.yaml</code></p>
<p>The task fails with errors indicating the the variables were not substituted as expected.</p>
<p>Here are the config excerpts:</p>
<p><strong>cloudbuild.yaml</strong></p>
<pre><code>//push image to container registry
    ....
    .......

  - id: &quot;deploy container image to GKE&quot;
    name: &quot;gcr.io/cloud-builders/gke-deploy&quot;
    args: [
    &quot;--cluster&quot;, &quot;${_CLUSTER_NAME}&quot;,
    &quot;run&quot;,
    &quot;--filename&quot;, &quot;deployment.yaml&quot;,
    &quot;--image&quot;, &quot;us-west1-docker.pkg.dev/$PROJECT_ID/abc/abc-server-${_DEPLOYMENT_TYPE}:$COMMIT_SHA&quot;,
    &quot;--location&quot;, &quot;${_COMPUTE_ZONE}&quot;
    ]
</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>    ....
    ........
    spec:
      containers:
        - name: idr-server-k8ts-test
          image: us-west1-docker.pkg.dev/$PROJECT_ID/abc/abc-server-${_DEPLOYMENT_TYPE}:$COMMIT_SHA
          ports:
            - containerPort: 8080
</code></pre>
<p><em>Vars defined in build trigger</em></p>
<pre><code>_CLUSTER_NAME
_DEPLOYMENT_TYPE
_COMPUTE_ZONE
</code></pre>
<p>I get the error:</p>
<p><code>Error: failed to prepare deployment: failed to update container of objects: failed to parse reference from image &quot;us-west1-docker.pkg.dev/$PROJECT_ID/abc/abc-server-${_DEPLOYMENT_TYPE}:$COMMIT_SHA&quot;: could not parse reference: us-west1-docker.pkg.dev/$PROJECT_ID/abc/abc-server-${_DEPLOYMENT_TYPE}:$COMMIT_SHA</code></p>

7guyo
<p>Kubernetes doesn't understand any variables written in manifest files. Your image's name (<code>us-west1-docker.pkg.dev/$PROJECT_ID/abc/abc-server-${_DEPLOYMENT_TYPE}:$COMMIT_SHA</code>) contains environment variables. Plain manifests require constant/hardcoded values.</p>
<p>If you want to populate your manifests dynamically through environment variables, create a <a href="https://helm.sh/" rel="nofollow noreferrer">helm chart</a> and apply it in the cluster.</p>
