> For the complete documentation index, see [llms.txt](https://learn.farizizwan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.farizizwan.com/devops-and-devsecops/kubernetes/poc-lab/configure-access-to-multiple-cluster-using-kube_config.md).

# Configure Access to Multiple Cluster using KUBE\_CONFIG

## **Scenario**

We have multiple K8s cluster:

1. A cluster in an on-premise environment (Microk8S)
2. A cluster on the Cloud environment (AWS)
3. A cluster on the Cloud environment (Digital Ocean)

You may create multiple config files under the `~/.kube/` directory.

Example:

```bash
┌─[admin@my-dev-svr] - [~/.kube] - [Mon May 22, 21:50]
└─[$]> tree
.
├── aws-cluster-01
├── do-k8s-01-kubeconfig
└── microk8s@home-cloud01.lab

0 directories, 3 files
┌─[admin@my-dev-svr] - [~/.kube] - [Mon May 22, 21:50]
└─[$]>
```

As you can see on the example above, `aws-cluster-01` is the config files for cluster that hosted on AWS, `do-k8s-01-kubeconfig` is for the cluster access on the Digital Ocean, while the last one `microk8s@home-cloud01.lab` is MicroK8s cluster that reside on the on-premise environment.

Then, you have to modify `.bash_profile` or `.zshrc` to combine all the access config into one liner KUBE\_CONFIG environment variable like the following:

```bash
#On Prem K8s
export CONFIG_MICROK8S=$HOME/.kube/microk8s@home-cloud01.lab

#Cloud K8s
export CONFIG_DO=$HOME/.kube/do-k8s-01-kubeconfig
export CONFIG_AWS=$HOME/.kube/aws-cluster-01

#Merge all the configs
export KUBECONFIG=$CONFIG_MICROK8S:$CONFIG_DO:$CONFIG_AWS
```

Finally, test the connectivity.

<figure><img src="/files/SYr8fdJ8OYc7gjR24N3D" alt=""><figcaption></figcaption></figure>

Gist Source: <https://gist.github.com/malikperang/82db3f21ac0fde6ab1752ce329f782e5>
