<p>I need to write a new Pulumi program to do some k8s stuff. One task is creating new namespaces in different clusters.</p>
<p>What I <em>want</em> to do should look like this:</p>
<pre class="lang-js prettyprint-override"><code>    const ns1 = new k8s.core.v1.Namespace(&quot;foo-ns&quot;, {cluster: &quot;foo_cluster&quot;});
    const ns2 = new k8s.core.v1.Namespace(&quot;bar-ns&quot;, {cluster: &quot;bar_cluster&quot;});
</code></pre>
<p>I've looked at the docs for Namespaces (<a href="https://www.pulumi.com/registry/packages/kubernetes/api-docs/core/v1/namespace/" rel="nofollow noreferrer">https://www.pulumi.com/registry/packages/kubernetes/api-docs/core/v1/namespace/</a>) and I'm not really sure how I can control where the namespaces will get created. I see that there is an option to pass in a cluster name (<a href="https://www.pulumi.com/registry/packages/kubernetes/api-docs/core/v1/namespace/#clustername_nodejs" rel="nofollow noreferrer">https://www.pulumi.com/registry/packages/kubernetes/api-docs/core/v1/namespace/#clustername_nodejs</a>) but the documents says</p>
<blockquote>
<p>The name of the cluster which the object belongs to. This is used to distinguish resources with same name and namespace in different clusters. <strong>This field is not set anywhere right now and apiserver is going to ignore it</strong> if set in create or update request.</p>
</blockquote>
<p>(emphasis is mine)</p>
<p>So now I wonder: if I tell Pulumi to create a new namespace, in which cluster will the namespace be created?</p>
<p>(I was going to also ask about creating namespaces in similarly-named clusters in different GKE environments in different GCP projects - as that might be the next phase of this code, but I don't see a point if I can't specify different clusters in the same project)</p>

FrustratedWithFormsDesigner
<p>You can achieve this using a resource provider, concretely, an explicit <a href="https://www.pulumi.com/docs/intro/concepts/resources/providers/#explicit-provider-configuration" rel="nofollow noreferrer">resource provider</a></p>
<p>The <a href="https://www.pulumi.com/registry/packages/kubernetes/api-docs/provider/" rel="nofollow noreferrer">Kubernetes resource provider</a> supports a variety of ways to configure access to clusters, such as passing a <code>kubeconfig</code> or Kubernetes context:</p>
<pre class="lang-js prettyprint-override"><code>import * as k8s from &quot;@pulumi/kubernetes&quot;;

const cluster1 = new k8s.Provider(&quot;cluster1&quot;, {
  cluster: &quot;cluster1&quot; // use the cluster with name &quot;cluster1&quot; in your default kubeconfig
});

const cluster2 = new k8s.Provider(&quot;cluster2&quot;, {
  kubeconfig: fs.readFileSync(path.resolve(__dirname, &quot;./kubeconfig.yaml&quot;) // use a different kubeconfig entirely
});

 const ns1 = new k8s.core.v1.Namespace(&quot;foo-ns&quot;, {}, {provider: cluster1});
 const ns2 = new k8s.core.v1.Namespace(&quot;bar-ns&quot;, {}, {provider: cluster2});

</code></pre>
