<p>I have started learning Kuberenetes for some time (not pro yet). I am using docker-desktop on Windows 11 with Kubernetes all works fine. But at some point I added AKS (Azure Kubernetes) cluster to my test lab and the AKS is deleted at later point from Azure Portal.</p>
<p>So when I run <code>kubectl config view</code> I get following output:</p>
<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://aksxxxxxxx-rg-aks-xxxxxx-xxxxxxxx.hcp.northeurope.azmk8s.io:443
  name: aksxxxxxxx
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://kubernetes.docker.internal:6443
  name: docker-desktop
contexts:
- context:
    cluster: docker-desktop
    user: docker-desktop
  name: docker-desktop
current-context: docker-desktop
kind: Config
preferences: {}
users:
- name: clusterUser_AKSRG_aksxxxxxxx
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
    token: REDACTED
- name: clusterUser_RG-AKS_aksxxxxxxx
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
    token: REDACTED
- name: docker-desktop
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
</code></pre>
<p>So what I did, I ran <code>kubectl config get-contexts</code> and deleted the unused aks using <code>kubectl config delete-context aksxxxxxxx</code> and now only one context, the docker-desktop</p>
<pre><code>CURRENT   NAME             CLUSTER          AUTHINFO         NAMESPACE
*         docker-desktop   docker-desktop   docker-desktop
</code></pre>
<p>Which is fine, my question was, How to clean up the view, so it does not view unused (dead) clusters and users that does not exist? Or am I taking the wrong approach?</p>

Maytham Fahmi
<p><code>kubectl config view</code> shows you your whole configuration under <em>.kube/config</em></p>
<p><code>kubectl config get-contexts</code> will give you an output about your contexts. A context is the allocation between cluster and user.</p>
<p>Since you only have deleted the allocation (context) you still have the cluster and user in your <em>.kube/config</em> which is the output of your <code>kubectl config view</code>.</p>
<p>To delete the cluster you can use <code>kubectl config delete-cluster aksxxxxxxx</code>.
To delete the user you can use <code>kubectl config unset users.clusterUser_RG-AKS_aksxxxxxxx</code></p>
