<p>I´m new to kubernetes an created a cluster on google cloud platform.
Now i´m trying to setup automated deployment from vsts an need to create a kubernetes user for this to get a kubeconfig file for authentication.</p>

<p>Now my question is how can i do this?
Do i need to create this user with kubectl (if yes how?)?
Or is there a way to create the user through gcp console?</p>

<p>I searched the web but found nothing that worked. Thanks for any suggestions!</p>

<p><strong>Edit:</strong>
I now how to connect to my cluster using this gcloud command: <code>gcloud container clusters get-credentials</code>. This work perfectly fine on my local dev machine.
But on my vsts build agent i dont have gcloud installed (and also dont want to install it) and need to use only kubectl to connect to my cluster without the gcloud command.</p>

<p>I have already figured out that the gcloud command creates a kubeconfig file with the gcloud command as auth provider (so i cant just copy the created kubeconifg file casue it depends on gcloud installed). When i then run kubectl it creates an temporary access token in the kubeconfig. But this token is only valid for about 30 minutes.
I need a token that is valid infinitely, so i can use this on my build server.</p>

<p>To connect to Kubernetes cluster in GCP, you can use either user or service account.  </p>

<p>If you choose user account, run this command:  </p>

<pre><code>gcloud init 
</code></pre>

<p>or  </p>

<pre><code>gcloud init --console-only
</code></pre>

<p>This will bring up GCP authentication dialog. When you pass authentication, you'll be able to operate with permission of the authenticated user.  </p>

<p>If you choose service account, you need to create it and generate a new key for it.  </p>

<p>You can do it using <em>GPC console</em> -> <em>IAM &amp; admin</em> -> <em>IAM</em> -> <em>Service accounts</em>.<br>
Click on <code>Create service account</code>, select name for the account, select the appropriate role, and click <code>Create</code>.<br>
You can generate the key by selecting <code>Furnish a new private key</code> in the account creation dialog box, or generate a new key by clicking on three dots on the right side of existed service account row and selecting <code>Create key</code>. Select JSON format and save the file on disk.  </p>

<p>Then run the command:  </p>

<pre><code>gcloud auth activate-service-account &lt;service@account.name&gt;  --key-file=&lt;previously_saved_file.json&gt;
</code></pre>

<p>At this stage, you are authenticated with CGP and ready to connect to your Kubernetes cluster:  </p>

<p>Next command will update your kubectl configuration to work with your cluster.  </p>

<pre><code>gcloud container clusters get-credentials &lt;cluster_name&gt; --zone &lt;gcp_availability_zone&gt; --project &lt;gcp_project_name&gt;
</code></pre>

<p>You can extend or decrease the account's permissions by selecting another role for it in GCP IAM management interface.   </p>

<p>Official documentation:<br>
<a href="https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account" rel="nofollow noreferrer">gcloud auth activate-service-account</a><br>
<a href="https://cloud.google.com/sdk/gcloud/reference/init" rel="nofollow noreferrer">gcloud init</a><br>
<a href="https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials" rel="nofollow noreferrer">gcloud container clusters get-credentials</a></p>
