<p>I have set up a Google Cloud Platform kubernetes cluster (and Container Registry) with source code on GitHub. Source code is divided into folders with separate Dockerfiles for each microservice.</p>
<p>I want to set up CI/CD using GitHub actions.</p>
<p>As far as I understand, the <a href="https://github.com/actions/starter-workflows/blob/d9236ebe5585b1efd5732a29ea126807279ccd56/ci/google.yml" rel="nofollow noreferrer">default GKE workflow</a> will connect to gcloud using secrets, build the images and push them to Container Registry. And then perform an update.</p>
<h2>My questions</h2>
<ul>
<li>How is the deployment performed?</li>
<li>What is <strong>kustomize</strong> for?</li>
<li>Do I have to configure on gcloud anything else than <strong>GKE key / token</strong></li>
<li>Suppose I want to update multiple docker images. Will it suffice to build multiple images and push them? Like below (a little bit simplified for clarity), or do I have to also modify the <strong>Deploy</strong> job:</li>
</ul>
<pre><code>    - name: Build
      run: |-
        docker build -t &quot;gcr.io/$PROJECT_ID/$IMAGE_1:$GITHUB_SHA&quot; service1/.
        docker build -t &quot;gcr.io/$PROJECT_ID/$IMAGE_2:$GITHUB_SHA&quot; service2/.
        docker build -t &quot;gcr.io/$PROJECT_ID/$IMAGE_3:$GITHUB_SHA&quot; service3/.

    - name: Publish
      run: |-
        docker push &quot;gcr.io/$PROJECT_ID/$IMAGE_1:$GITHUB_SHA&quot;
        docker push &quot;gcr.io/$PROJECT_ID/$IMAGE_2:$GITHUB_SHA&quot;
        docker push &quot;gcr.io/$PROJECT_ID/$IMAGE_3:$GITHUB_SHA&quot;
</code></pre>
<hr />
<p>This is the deploy fragment from the GKE workflow:</p>
<pre><code>    # Deploy the Docker image to the GKE cluster
    - name: Deploy
      run: |-
        ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
        ./kustomize build . | kubectl apply -f -
        kubectl rollout status deployment/$DEPLOYMENT_NAME
        kubectl get services -o wide
</code></pre>

<p>I just wanted to share my experience with GKE after posting this question and then implementing the GitHub action.</p>
<blockquote>
<p>How is the deployment performed?</p>
</blockquote>
<p>Basically, the workflow sets up a connection to GKE via <strong>gcloud</strong> CLI (this also sets up <strong>kubectl</strong> context).<br />
After the connection is established and the correct cluster targeted you are free to do whatever you like.</p>
<blockquote>
<p>Do I have to configure on gcloud anything else than GKE key / token</p>
</blockquote>
<p>Nothing else is required. Just remember to hash it correctly and store it in a secret on GitHub.</p>
<blockquote>
<p>Suppose I want to update multiple docker images...</p>
</blockquote>
<p>Doing it the way it is in a question is absolutely valid and fully functional.</p>
<blockquote>
<p>...or do I have to also modify the Deploy job</p>
</blockquote>
<p>I decided to change the Deploy a little bit.</p>
<pre><code># Deploy update to services
- name: Deploy
  run: |-
    kubectl set image deployment dep1 dep1=&quot;gcr.io/$PROJECT_ID/$IMAGE_1:$GITHUB_SHA&quot;
    kubectl set image deployment dep2 dep2=&quot;gcr.io/$PROJECT_ID/$IMAGE_2:$GITHUB_SHA&quot;
</code></pre>
<p>This way I don't have to use <strong>Kustomize</strong> that I am not familiar with.<br />
If you have the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy" rel="nofollow noreferrer">update strategy</a> set to RollingUpdate <em>- - which I believe is the default - -</em> the change in image tag will trigger the rolling update (other strategies may work as well). But to use this approach you have to use the same image tag in building Docker images and deploying them using the code above. Using the <a href="https://docs.github.com/en/github/getting-started-with-github/github-glossary#commit-id" rel="nofollow noreferrer">$GITHUB_SHA</a> will provide a distinct hash for a commit that can be used to differentiate docker images.</p>
<p>This may not be the most elegant solution but I am sure you can come up with a better solution (like obtaining the release Tag) because this is just a variable.</p>
