Kubeconfig is a file that you can use to switch multiple clusters by switching context. We can use kubectl config view to view the setting and the kubectl config current-context command to check the context you're currently using. The following is an example of a GCP cluster in a kubeconfig file:
# kubectl config view apiVersion: v1 clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://35.0.0.200
name: gke_devops-with-kubernetes_us-central1-b_cluster
contexts:
- context:
cluster: gke_devops-with-kubernetes_us-central1-b_cluster
user: gke_devops-with-kubernetes_us-central1-b_cluster
name: gke_devops-with-kubernetes_us-central1-b_cluster
current-context: gke_devops-with-kubernetes_us-central1-b_cluster
kind: Config
preferences: {}
users:
- name: gke_devops-with-kubernetes_us-central1-b_cluster
user:
auth-provider:
config:
access-token: XXXXX
cmd-args: config config-helper --format=json
cmd-path: /Users/devops/k8s/bin/gcloud
expiry: 2018-12-16T02:51:21Z
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
As we learned previously, we can use kubectl config use-context CONTEXT_NAME to switch the context. We can also specify kubeconfig files according to the $KUBECONFIG environment variable to determine which kubeconfig files are used. In this way, config files could be merged. For example, the following command will merge kubeconfig-file1 and kubeconfig-file2:
export KUBECONFIG=$KUBECONFIG: kubeconfig-file1: kubeconfig-file2
By default, the kubeconfig file is located at $HOME/.kube/config. This file will be loaded if none of the preceding settings are set.