<p>What is the standard approach to getting GCP credentials into k8s pods when using skaffold for local development? </p>

<p>When I previously used docker compose and aws it was easy to volume mount the ~/.aws folder to the container and everything just worked. Is there an equivalent solution for skaffold and gcp?</p>

<blockquote>
<p>When I previously used docker compose and aws it was easy to volume
mount the ~/.aws folder to the container and everything just worked.
Is there an equivalent solution for skaffold and gcp?</p>
</blockquote>
<p>You didn't mention what kind of <strong>kubernetes cluster</strong> you have deployed locally but if you use <strong>Minikube</strong> it can be actually achieved in a very similar way.</p>
<p>Supposed you have already initialized your <strong>Cloud SDK</strong> locally by running:</p>
<pre><code>gcloud auth login
gcloud container clusters get-credentials &lt;cluster name&gt; --zone &lt;zone&gt; --project &lt;project name&gt;
gcloud config set project &lt;project name&gt;
</code></pre>
<p>so you can run your <code>gcloud commands</code> on the local machine on which <strong>Minikube</strong> is installed. You can easily delagate this access to your <code>Pods</code> created either by <strong>Skakffold</strong> or manually on <strong>Minikube</strong>.</p>
<p>You just need to start your <strong>Minikube</strong> as follows:</p>
<pre><code>minikube start --mount=true --mount-string=&quot;$HOME/.config/gcloud/:/home/docker/.config/gcloud/&quot;
</code></pre>
<p>To make things simple I'm mounting local <strong>Cloud SDK</strong> config directory into <strong>Minikube</strong> host using as a mount point <code>/home/docker/.config/gcloud/</code>.</p>
<p>Once it is available on <strong>Minikube host VM</strong>, it can be easily mounted into any <code>Pod</code>. We can use one of the <strong>Cloud SDK</strong> docker images available <a href="https://hub.docker.com/r/google/cloud-sdk/" rel="nofollow noreferrer">here</a> or any other image that comes with <strong>Cloud SDK</strong> preinstalled.</p>
<p>Sample <code>Pod</code> to test this out may look like the one below:</p>
<pre><code>apiVersion: v1
kind: Pod 
metadata:
  name: cloud-sdk-pod
spec:
  containers:
  - image: google/cloud-sdk:alpine
    command: ['sh', '-c', 'sleep 3600']
    name: cloud-sdk-container
    volumeMounts:
    - mountPath: /root/.config/gcloud
      name: gcloud-volume
  volumes:
  - name: gcloud-volume
    hostPath:
      # directory location on host
      path: /home/docker/.config/gcloud
      # this field is optional
      type: Directory
</code></pre>
<p>After connecting to the <code>Pod</code> by running:</p>
<pre><code>kubectl exec -ti cloud-sdk-pod -- /bin/bash
</code></pre>
<p>we'll be able to execute any <code>gcloud</code> commands as we are able to execute them on our local machine.</p>
