<p>I am using the standalone <a href="https://docs.docker.com/docker-for-mac/kubernetes/" rel="nofollow noreferrer">Kubernetes</a> server and client that docker desktop includes.</p>
<p>I created two namespaces for k8s named: <code>development</code> and <code>production</code>.</p>
<pre><code>☁  kubernetes-labs [master] ⚡  k get namespace
NAME              STATUS   AGE
default           Active   3d22h
development       Active   2d23h
kube-node-lease   Active   3d23h
kube-public       Active   3d23h
kube-system       Active   3d23h
production        Active   5m1s
</code></pre>
<p>Then, set a new cluster named <code>kubernetes-labs</code>:</p>
<pre><code>☁  kubernetes-labs [master] ⚡  k config set-cluster kubernetes-labs --server=https://kubernetes.docker.internal:6443
Cluster &quot;kubernetes-labs&quot; set.
</code></pre>
<p>As you can see, the new cluster's server point to <code>https://kubernetes.docker.internal:6443</code> which is used by the standalone Kubernetes server.</p>
<p>Next, created two contexts:</p>
<pre><code>☁  kubernetes-labs [master] ⚡  kubectl config set-context kubernetes-labs-dev --cluster=kubernetes-labs --namespace=development --user=dev
Context &quot;kubernetes-labs-dev&quot; modified.
☁  kubernetes-labs [master] ⚡  kubectl config set-context kubernetes-labs-prod --cluster=kubernetes-labs --namespace=production --user=prod
Context &quot;kubernetes-labs-prod&quot; created.
</code></pre>
<p>Switch to <code>kubernetes-labs-dev</code> context:</p>
<pre><code>☁  kubernetes-labs [master] ⚡  k config use-context kubernetes-labs-dev
Switched to context &quot;kubernetes-labs-dev&quot;.
</code></pre>
<p>Now, when I try to get pods from the current namespace:</p>
<pre><code>☁  kubernetes-labs [master] ⚡  k get pods                                                                           
Please enter Username: dev
Please enter Password: 
</code></pre>
<p>Need an authentication, I don't know what <code>username</code> and <code>password</code> should be entered.</p>
<p>Besides, when I try to view the config used by the current context, got an error.</p>
<pre class="lang-sh prettyprint-override"><code>☁  kubernetes-labs [master] ⚡  k config view --minify=true    
error: cannot locate user dev
</code></pre>

<p>In order to make it work you need to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/" rel="nofollow noreferrer">Configure Access to Multiple Clusters</a>:</p>
<blockquote>
<p>This page shows how to configure access to multiple clusters by using
configuration files. After your clusters, users, and contexts are
defined in one or more configuration files, you can quickly switch
between clusters by using the kubectl config use-context command.</p>
</blockquote>
<p>You need to make sure that your configuration file is correct. A configuration file describes clusters, users, and contexts. Than, you can add users details to your configuration file, for example:</p>
<pre><code>kubectl config --kubeconfig=config-demo set-credentials developer --client-certificate=fake-cert-file --client-key=fake-key-seefile
kubectl config --kubeconfig=config-demo set-credentials experimenter --username=exp --password=some-password
</code></pre>
<p>The same can be done with contexts, for example:</p>
<pre><code>kubectl config --kubeconfig=config-demo set-context dev-frontend --cluster=development --namespace=frontend --user=developer
kubectl config --kubeconfig=config-demo set-context dev-storage --cluster=development --namespace=storage --user=developer
kubectl config --kubeconfig=config-demo set-context exp-scratch --cluster=scratch --namespace=default --user=experimenter
</code></pre>
<p>and clusters, for example:</p>
<pre><code>kubectl config --kubeconfig=config-demo set-cluster development --server=https://1.2.3.4 --certificate-authority=fake-ca-file
kubectl config --kubeconfig=config-demo set-cluster scratch --server=https://5.6.7.8 --insecure-skip-tls-verify
</code></pre>
<p>Bear in mind that you need to set the proper pathnames of the certificate files in your environment for your configuration file to work properly.</p>
<p>Also, remember that:</p>
<blockquote>
<p>Each context is a triple (cluster, user, namespace). For example, the
dev-frontend context says, &quot;Use the credentials of the developer user
to access the frontend namespace of the development cluster&quot;.</p>
</blockquote>
<p>You can find more details and examples in the linked documentation. The step by step guide will make it easier for you to setup properly.</p>
