<pre><code>KUBECONFIG=&quot;$(find ~/.kube/configs/ -type f -exec printf '%s:' '{}' +)&quot;
</code></pre>
<p>This will construct a config file path for the environment var. I can see the contexts of my clusters and I can switch them. However when I want to get my nodes I get</p>
<blockquote>
<p>error: You must be logged in to the server (Unauthorized)</p>
</blockquote>
<p>How to solve, any ideas?</p>

Stephan Kristyn
<p>I suspect you either don't have a <code>current-context</code> set or your <code>current-context</code> points to a non-functioning cluster.</p>
<p>If set (or exported) <code>KUBECONFIG</code> can reference a set of config files.</p>
<p>The files' content will be merged. I think this is what you're attempting.</p>
<p>But then, that variable must be exported for <code>kubectl</code> to use.</p>
<p>Either:</p>
<pre class="lang-sh prettyprint-override"><code>export KUBECONFIG=...
kubectl ...
</code></pre>
<p>Or:</p>
<pre class="lang-sh prettyprint-override"><code>KUBECONFIG=... kubectl ...
</code></pre>
<p>Then, you can:</p>
<pre class="lang-sh prettyprint-override"><code># List contexts by NAME
kubectl config get-contexts

# Use one of them by NAME
kubectl config use-context ${NAME}
</code></pre>
