# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.farizizwan.com/devops-and-devsecops/kubernetes/poc-lab/configure-access-to-multiple-cluster-using-kube_config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
