<p>I created an Kubernetes Cluster in Google Cloud, I'm using my macbook to create PODs, and I'm using <code>gcloud</code> to connect to cluster from my computer:</p>

<p><a href="https://i.stack.imgur.com/DjKb5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DjKb5.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/TgqTe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TgqTe.png" alt="enter image description here"></a></p>

<p>When I run <code>gcloud container clusters get-credentials gcloud-cluster-dev --zone europe-west1-d --project ***********</code> in my computer, <code>gcloud</code> configures automatically <code>~/.kube/config</code> file.</p>

<p>But now I want to connect to kubectl from a Docker container (this one: <code>dtzar/helm-kubectl:2.14.0</code>), and I don't want to use <code>gcloud</code>, I only want to use <code>kubectl</code>.</p>

<p>When I run <code>docker run -it dtzar/helm-kubectl:2.14.0 sh</code>, I already have <code>kubectl</code> installed, but not configurated to connect to cluster.</p>

<p>I'm trying to connect <code>kubectl</code> to cluster without installing <code>gcloud</code>.</p>

<p>I tried basic authentication <a href="https://blog.christianposta.com/kubernetes/logging-into-a-kubernetes-cluster-with-kubectl/" rel="nofollow noreferrer">https://blog.christianposta.com/kubernetes/logging-into-a-kubernetes-cluster-with-kubectl/</a> without success.
Returns an error:</p>

<pre><code># kubectl get pods
error: You must be logged in to the server (Unauthorized)

# kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
error: You must be logged in to the server (the server has asked for the client to provide credentials)
</code></pre>

<p>I also tried this: <a href="https://codefarm.me/2019/02/01/access-kubernetes-api-with-client-certificates/" rel="nofollow noreferrer">https://codefarm.me/2019/02/01/access-kubernetes-api-with-client-certificates/</a>
But I don't found where are <code>ca.crt</code> and <code>ca.key</code> to use in this line: <code>(...) -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key (...)</code></p>

<p>I only see this:
<a href="https://i.stack.imgur.com/LhM20.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LhM20.png" alt="enter image description here"></a></p>

<p>Can I use this CA? How?</p>

<p>Anyone can help me? Thanks.</p>

<p><strong>EDIT:</strong>
I can't mount my kubectl config in the docker image, because I created this config with gcloud, and the Docker image don't have gcloud. I want to connect directly to kubectl withou gcloud</p>

<pre class="lang-sh prettyprint-override"><code>
$ docker run -v ~/.kube:/root/.kube -it dtzar/helm-kubectl:2.14.0 sh

# kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Unable to connect to the server: error executing access token command "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=fork/exec /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud: no such file or directory output= stderr=
</code></pre>

Rui Martins
<p>The easiest would be to mount your ~/.kube/config into your container. Like:</p>

<pre><code>docker run -v ~/.kube:/root/.kube &lt;your container image:tag&gt; 
</code></pre>

<p><strong>EDIT:</strong> If this is not enough, you can, also, mount your sdk folder (kinda hackish):</p>

<pre><code>docker run -v ~/.kube:/root/.kube -v /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk:/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk -it dtzar/helm-kubecsh:2.14.0 sh
</code></pre>
