<p>I am doing an exercise from KodeKoud which provide the CKAD certification training.</p>
<p>The exercise has a <code>my-kube-config.yml</code> file located under <code>root/</code>. The file content is below:</p>
<p>(I ommited some unrelated parts)</p>
<pre><code>apiVersion: v1
kind: Config

clusters:
- name: production
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

- name: development
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

- name: test-cluster-1
  cluster:
    certificate-authority: /etc/kubernetes/pki/ca.crt
    server: https://controlplane:6443

contexts:

- name: test-user@production
  context:
    cluster: production
    user: test-user

- name: research
  context:
    cluster: test-cluster-1
    user: dev-user

users:
- name: test-user
  user:
    client-certificate: /etc/kubernetes/pki/users/test-user/test-user.crt
    client-key: /etc/kubernetes/pki/users/test-user/test-user.key
- name: dev-user
  user:
    client-certificate: /etc/kubernetes/pki/users/dev-user/developer-user.crt
    client-key: /etc/kubernetes/pki/users/dev-user/dev-user.key


current-context: test-user@development
</code></pre>
<p>The exercise asking me to:</p>
<blockquote>
<p>use the <code>dev-user</code> to access <code>test-cluster-1</code>. Set the current context
to the right one so I can do that.</p>
</blockquote>
<p>Since I see in the config file, there is a context named <code>research</code> which meets the requirement, so I run the following command to change the current context to the required one:</p>
<pre><code>kubectl config use-context research
</code></pre>
<p>but the console gives me error: <code>error: no context exists with the name: &quot;research&quot;</code>.</p>
<p>Ok, I guessed maybe the <code>name</code> with value <code>research</code> is not acceptable, maybe I have to follow the convention of <code>&lt;user-name&gt;@&lt;cluster-name&gt;</code>? I am not sure , but I then tried the following:</p>
<ol>
<li>I modified the name from <code>research</code> to <code>dev-user@test-cluster-1</code>, so that context part becomes:</li>
</ol>
<pre><code>- name: dev-user@test-cluster-1
  context:
    cluster: test-cluster-1
    user: dev-user
</code></pre>
<ol start="2">
<li>after that I run command: <code>kubectl config use-context dev-user@test-cluster-1</code>, but I get error:</li>
</ol>
<pre><code>error: no context exists with the name: &quot;dev-user@test-cluster-1&quot;
</code></pre>
<p>Why? Based on the course material that is the way to chagne the default/current context. Is the course out-dated that I am using a deprecated one? What is the problem?</p>

user842225
<p>Your initial idea was correct. You would need to change the context to <code>research</code> which can be done using</p>
<blockquote>
<p>kubectl config use-context research</p>
</blockquote>
<p>But the command would not be applied to the correct config in this instance. You can see the difference by checking the current-context with and without a kubeconfig directed to the <code>my-kube-config</code> file.</p>
<blockquote>
<p>kubectl config current-context</p>
<p>kubernetes-admin@kubernetes</p>
</blockquote>
<blockquote>
<p>kubectl config --kubeconfig=/root/my-kube-config current-context</p>
<p>test-user@development</p>
</blockquote>
<p>So run the <code>use-context</code> command with the correct kubeconfig</p>
<blockquote>
<p>kubectl config --kubeconfig=/root/my-kube-config use-context research</p>
</blockquote>
