/
Merging Kubernetes kubectl config files

Merging Kubernetes kubectl config files

  • To run a kubernetes cluster check whether the path of that cluster should be present in “~/ .kube/config” folder.If not there, we need to add the path of the cluster to that folder.

  • To check whether the path is present in “~/ .kube/config” folder.

$ echo $KUBECONFIG
  • If path is absent follow the below commands:

  • $ export KUBECONFIG=~/.kube/config:PATH OF THE CLUSTER $ kubectl config view --flatten >> ~/.kube/config $ echo $KUBECONFIG
  • To display the cluster contexts

$ kubectl config get-contexts
  • Sometimes when working with a new Kubernetes cluster you will be given a config file to use when authenticating with the cluster. This file should be placed at ~/.kube/config. However you may already have an existing config file at that location and you need to merge them together.

  • To merge the config files in “~/ .kube/config” follow the below steps:

# Make a copy of your existing config $ cp ~/.kube/config ~/.kube/config.bak
  • It will create a backup file for existing config file.

consider eks_gowtham_eks = path1

eks_Gowtham_cicd = path2

  • Add those paths using following command

$ export KUBECONFIG=path1:path2 $ kubectl config view --flatten >> ~/.kube/config
  • After adding the paths check they had added or not

$ kubectl config get-contexts
  • If you want to switch the contexts

$ kubectl config use-context eks_gowtham-eks
$ kubectl config get-contexts
  • Finally check whether all the pods are running.

$ kubectl get pods -A

 

Related content