<p><strong>Background</strong></p>

<p>We're using Jenkins to deploy a new version of a Kubernetes (k8s) replication controller to our test or prod cluster. The test and prod (k8s) clusters are located under different (google cloud platform) projects. We have configured two profiles for our gcloud SDK on Jenkins, one for test (test-profile) and one for prod (prod-profile). We have defined a managed script in Jenkins that performs the rolling update for our replication controller. The problems is that I cannot find a way to control to which project I want to target the <code>kubectl rolling-update</code> command (you can specify which cluster but not which project afict). So right now our script that does the rolling update to our test server looks something like this:</p>

<pre><code>gcloud config configurations activate test-profile &amp;&amp; kubectl rolling-update ...
</code></pre>

<p>While this works it could be extremely dangerous if two jobs run concurrently for different environments. Say that job 1 targets the test environment and job 2 targets prod. If job2 switches the active profile to "prod-profile" before job 1 has executed its <code>rolling-update</code> command job 1 will target to wrong project and in worse case update the wrong replication controller (if the clusters have the same name).</p>

<p><strong>Question</strong></p>

<p>Is there a way to specify which project that a kubectl command is targeting (for example during a rolling update) that is safe to run concurrently?</p>

<p>You can pass the <code>--cluster=</code> or <code>--context=</code> flags to kubectl to set a single run.  For example, if I have two clusters in my ~/.kube/config "foo" and "bar":</p>

<pre><code>$ kubectl --cluster=foo get pods
NAME              READY     STATUS    RESTARTS   AGE
foo-ht1qh   1/1       Running   0          3h
foo-wf8f4   1/1       Running   0          3h
foo-yvgpd   1/1       Running   0          3h
</code></pre>

<p>vs</p>

<pre><code>$ kubectl --cluster=bar get pods
NAME              READY     STATUS    RESTARTS   AGE
bar-de4h7   1/1       Running   0          9h
bar-c4g03   1/1       Running   0          9h
bar-2sprd   1/1       Running   0          9h
</code></pre>
