Kube config

Kube config is a configuration file that is used to define and manage access to Kubernetes cluster. It consists of Kubernetes cluster details, certificates and secret token to authenticate to the cluster

  1. When you use kubectl, it uses the information in the kubeconfig file to connect to the Kubernetes cluster API.

  2. The default location of the kubeconfig file is $HOME/.kube/config
    You can view the kubeconfig file inside home and then .kube directory and then the config file.

cd /home/abi/.kube/
cat config

Kubeconfig file structure

It has 3 sections

  1. clusters

  2. contexts

  3. users

sample kubeconfig file :

apiVersion: v1
kind: Config
- name: abi-cluster
    server: https://abi-cluster.example.com
    certificate-authority-data: <base64-encoded-ca-data>
- name: abi-context
    cluster: abi-cluster
    user: abi-user
    namespace: default
current-context: abi-context
- name: abi-user
    client-certificate-data: <base64-encoded-client-cert>
    client-key-data: <base64-encoded-client-key>


kubectl config view
kubectl config --kubeconfig=/root/my-config view # shows the config file present in the /root path 
kubectl config current-context # shows the current context for kubectl
kubectl config --kubeconfig=/root/my-config current-context #shows the current context for config file present in the /root path
kubectl config use-context aksdemo1 # switch context
kubectl cluster-info # shows Cluster Information
kubectl cluster-info # shows cluster information

suppose we want to set our config file as default config file then, we have to copy our config file to the default config path ~/.kube/config

cp /root/my-kube-config ~/.kube/config