<p>Is there a way to get the current kubernetes context at runtime to prevent calling <code>pulumi up</code> with the incorrect context? I'd specifically like to make sure my local kubernetes deployment logic doesn't end up in anything other than a local cluster.</p>

<p>I've gone through the examples and don't see anything that does this: <a href="https://github.com/pulumi/examples/search?l=TypeScript&amp;p=2&amp;q=context&amp;type=" rel="nofollow noreferrer">https://github.com/pulumi/examples/search?l=TypeScript&amp;p=2&amp;q=context&amp;type=</a> (maybe I'm thinking about my problem the wrong way).</p>

<p>As explained <a href="https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/" rel="nofollow noreferrer">here</a>, first you have to create a context for your cluster that will be used, for example:</p>

<pre><code>kubectl config \
    set-context &lt;my-context&gt; \
    --cluster=&lt;my-cluster&gt; \
    --user=&lt;my-user&gt;
</code></pre>

<p>Then run <code>pulumi stack init new-kube-stack</code> where you will be asked to enter your access token and finally run <code>pulumi config set kubernetes:context my-context</code> to work in a cluster defined in previously created context. </p>
