<p>I am unable to connect to our Kubernetes cluster. The <code>kubectl</code> command does not seem to take the configuration into account...</p>
<p>When I issue a <code>kubectl cluster-info</code> (or <code>kubectl get pods</code>)
I get the following error message:</p>
<blockquote>
<p>The connection to the server localhost:8080 was refused - did you specify the right host or port?</p>
</blockquote>
<p>I was suspecting that the <code>~/.kube/config</code> was pointing to my minikube  but it is not the case:</p>
<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS...==
    server: https://10.95.xx.yy:6443
  name: cluster.local
contexts:
- context:
    cluster: cluster.local
    namespace: xxx-cluster-xxx-xx-username
    user: username
  name: username-context
current-context: &quot;&quot;
kind: Config
preferences: {}
users:
- name: username
  user:
    client-certificate: .certs/username.crt
    client-key: .certs/username.key

</code></pre>
<p>Surprisingly, the <code>$KUBECONFIG</code> environment variable is set to the correct path:</p>
<pre><code>KUBECONFIG=/Users/username/.kube/config

</code></pre>
<p>and the <code>kubectl config view</code> works fine (a.k.a. is not pointing to <code>localhost</code> but to <code>https://10.95.xx.yy:6443</code>)</p>
<p>Finally, I also try to specify the path to the config file when invoking <code>kubectl</code> (<code>kubectl get pods --kubeconfig=/Users/username/.kube/config</code>), but the error remains the same...</p>

E. Jaep
<p>Your current context is unset, as seen with <code>current-context: &quot;&quot;</code>; if you were to run <code>kubectl --context username-context get pods</code> I would expect it to do more what you want. If that turns out to be the case, one can run <code>kubectl config use-context username-context</code> to set the <code>current-context</code> going forward</p>
