<p>I setup my Kubernetes cluster using kops, and I did so from local machine.  So my <code>.kube</code> directory is stored on my local machine, but I setup <code>kops</code> for state storage in <code>s3</code>.</p>
<p>I'm in the process of setting up my CI server now, and I want to run my <code>kubectl</code> commands from that box. How do I go about importing the existing state to that server?</p>

djt
<p>To run <code>kubectl</code> command, you will need the cluster's apiServer URL and related credentials for authentication. Those data are by convention stored in <code>~/.kube/config</code> file. You may also view it via <code>kubectl config view</code> command.</p>

<p>In order to run <code>kubectl</code> on your CI server, you need to make sure the <code>~/.kube/config</code> file contains all the information that <code>kubectl</code> client needs. </p>

<p>With kops, a simple naive solution is to:</p>

<p>1) install kops, kubectl on your CI server</p>

<p>2) config the AWS access credential on your CI server (either via IAM Role or simply env vars), make sure it has access to your s3 state store path</p>

<p>3) set env var for kops to access your cluster:</p>

<pre><code>  export NAME=${YOUR_CLUSTER_NAME}
  export KOPS_STATE_STORE=s3://${YOUR_CLUSTER_KOPS_STATE_STORE}
</code></pre>

<p>4) Use kops export command to get the kubecfg needed for running kubectl</p>

<pre><code>  kops export kubecfg ${YOUR_CLUSTER_NAME}
</code></pre>

<p>see <a href="https://github.com/kubernetes/kops/blob/master/docs/cli/kops_export.md" rel="noreferrer">https://github.com/kubernetes/kops/blob/master/docs/cli/kops_export.md</a></p>

<p>Now the <code>~/.kube/config</code> file on your CI server should contain all the information <code>kubectl</code> needs to access your cluster.</p>

<p>Note that this will use the default admin account on your CI server. To implement a more secure CI/CD environment, you should create a service account bind to a required permission scope (a namespace or type or resources for example), and place its credential on your CI server machine.</p>
