← All notes

Kubernetes kubeconfig files - contexts, the KUBECONFIG variable and merge rules

Answer: By default kubectl uses $HOME/.kube/config; specify other kubeconfig files with the KUBECONFIG environment variable or the --kubeconfig flag. Define contexts that each group a cluster, namespace and user, and switch with kubectl config use-context <name>.

Commands

kubectl config view
kubectl config get-contexts
kubectl config use-context staging
kubectl config set-context --current --namespace=team-a
KUBECONFIG=$HOME/.kube/config:$HOME/.kube/staging kubectl config view --flatten
kubectl --kubeconfig ./ci-config get pods

Example file

apiVersion: v1
kind: Config
clusters:
- name: development
  cluster:
    server: https://k8s.example.org/k8s/clusters/c-xxyyzz
    proxy-url: http://proxy.example.org:3128
users:
- name: developer
contexts:
- name: development
  context:
    cluster: development
    user: developer
    namespace: default
current-context: development

Merge rules

Paths and safety

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Organizing Cluster Access Using kubeconfig Files; kubernetes/website (GitHub), organize-cluster-access-kubeconfig.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Organizing Cluster Access Using kubeconfig Files; kubernetes/website (GitHub), organize-cluster-access-kubeconfig.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.

Cite this

Permanent ID: iil:note:0eacjwqe

iinventedlight. 2026. "Kubernetes kubeconfig files - contexts, the KUBECONFIG variable and merge rules." iinventedlight Library, iil:note:0eacjwqe, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-kubeconfig/. License: CC-BY-4.0.

@misc{iil_note_0eacjwqe,
  author = {{iinventedlight}},
  title = {{Kubernetes kubeconfig files - contexts, the KUBECONFIG variable and merge rules}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/kubernetes-kubeconfig/},
  note = {Permanent ID iil:note:0eacjwqe. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-kubeconfig.md.