logo

Kubernetes - kubeconfig

Last Updated: 2023-10-21

kubeconfig: contains info for clients (e.g. kubectl by users, kubelet, kube-controller-manager, kube-proxy, kube-scheduler) to talk to api server. Can be found in /etc/kubernetes.

Config

To check the current config:

$ kubectl config view

Default kubeconfig: $HOME/.kube/config

On admin node: /etc/kubernetes/admin.conf

To talk to a different cluster:

$ kubectl --kubeconfig /path/to/kubeconfig

A config has multiple contexts.

kubeconfig is a Config:

apiVersion: v1
kind: Config

Context

TL;DR: context = a cluster + a user + a namespace (Each of the three is optional)

A context in Kubernetes is a group of access parameters. Each context contains a Kubernetes cluster, a user, and a namespace. The current context is the cluster that is currently the default for kubectl: all kubectl commands run against that cluster. Each of the context that have been used will be available on your .kubeconfig.

A context is the connection to a specific cluster (username/apiserver host) used by kubectl.

"Context" only applies in the kubernetes client-side (where you run the kubectl command); kubernetes server-side doesn't recognize the term 'context'.

# Show current context
$ kubectl config current-context

# Get all contexts
$ kubectl config get-contexts

Stored as a Secret

kubeconfig may be stored as a Secret.

Remove from kubeconfig

E.g. kind export will add cluster info to the default config ~/.kube/config. To remove it:

  • kubectl config unset clusters.CLUSTER_NAME
  • kubectl config unset contexts.CONTEXT_NAME
  • kubectl config unset users.USER_NAME