<p>By default, <code>kubectl</code> configuration is located at <code>~/.kube/config</code>. Is it possible to specify the kubeconfig file explicitly when using the <code>kubectl</code> command?</p>

<p><code>kubectl</code> can use the <code>KUBECONFIG</code> in three different ways:</p>
<ol>
<li><p>Using the <code>KUBECONFIG</code> present in <code>~/.kube/config</code> if nothing is specified in <code>kubectl</code> command.</p>
</li>
<li><p>Using the <code>KUBECONFIG</code> defined by using the <code>KUBECONFIG</code> environment variable if nothing is specified in <code>kubectl</code> command.</p>
</li>
<li><p>Passing the <code>KUBECONFIG</code> as part of the <code>kubectl</code> command using the <code>--kubeconfig</code> flag as:</p>
<pre><code>kubectl --kubeconfig=&lt;KUBECONFIG_PATH&gt;
</code></pre>
</li>
</ol>
<p>Further, the order of precedence is as follows:</p>
<ol>
<li>Use the <code>KUBECONFIG</code> if explicitly passed in the <code>kubectl</code> command</li>
<li>Use the <code>KUBECONFIG</code> from the environment variable if <code>--kubeconfig</code> flag is not specified but the environment variable is set.</li>
<li>Use the <code>KUBECONFIG</code> from <code>~/.kube/config</code> if both <code>--kubeconfig</code> and <code>KUBECONFIG</code> are not specified.</li>
</ol>
