How to configure access to multiple clusters by using kubectl

Bhandarenakul
2 min readNov 9, 2021

As you know Kubernetes is used worldwide for deploying applications and its services with help of different cloud providers. it will be going to be so hectic to manage different clusters of different cloud providers.

So we can manage there all the different clusters of different cloud providers by centralizing them at our local system and handling them with the Kubernetes command-line (i.e kubectl) with help of kubecofig files.

What is kubeconfig file?

kubeconfig is a YAML file that contains either a username and password combination or a secure token that when read programmatically removes the need for the Kubernetes client to ask for interactive authentication. kubeconfig is the secure and standard method to enable access to your Kubernetes clusters.

How to access kubecofig file?

The default kubectl configuration file is located at ~/. Kube/config and is referred to as the kubeconfig file. kubeconfig files organize information about clusters, users, namespaces, and authentication mechanisms.

How to use kubectl to manage multiple clusters?

Below are the commands we can use to manage different cluster config files.

To list all kubeconfig :

$ kubectl config get-contexts

To switch between multiple kubeconfigs:

$ kubectl config use-context CONTEXT_NAME

To see which is the current config used by kubectl:

$ kubectl config current-context

To see kubeconfig content:

$ kubectl config view

How to access cluster information using kubectl?

After using the above commands to handle multiple cluster kubeconfig we can able access cluster information like pods, deployments, services, etc … information. we can use the below-documented commands to get cluster information

How to manage AWS, GCP clusters using kubectl?

To manage AWS, GCP, or any public or private cloud provider cluster using kubectl we will be required only cluster config. now the question is how we can get these cluster configs of different cloud providers? there is a different provision available to get cluster config across different cloud providers.

We can get cluster config at our local system using command line or APIs provided by cloud providers. we must have installed either CLI/Postman.

To Get AWS EKS Cluster Config:

$ aws eks update-kubeconfig — name <cluster_name>

To Get GCP Kubernetes Engin Cluster Config:

$ gcloud container clusters get-credentials <cluster_name>

The above command will generate a copy of the Kubernetes cluster config at the default config file location i.e ~/. Kube/config

Now after getting cluster config at our local system we can get all requested information about any cluster from the Public or Private cloud as mentioned above.

--

--