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
When you use kubectl, it uses the information in the kubeconfig file to connect to the Kubernetes cluster API.
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
clusters
contexts
users
sample kubeconfig file :
apiVersion: v1
kind: Config
clusters:
- name: abi-cluster
cluster:
server: https://abi-cluster.example.com
certificate-authority-data: <base64-encoded-ca-data>
contexts:
- name: abi-context
context:
cluster: abi-cluster
user: abi-user
namespace: default
current-context: abi-context
users:
- name: abi-user
user:
client-certificate-data: <base64-encoded-client-cert>
client-key-data: <base64-encoded-client-key>
Commands:
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