kubectl connects multiple clusters

1. Scene

We may have multiple kubernetes clusters in actual production, and we may need to access multiple clusters from one machine earlier.

2. Generate a fusion configuration file

This example demonstrates the configuration file (config) file of two clusters and executes the command on the console:

KUBECONFIG=第一个配置文件:第二个配置文件 kubectl config view --flatten

At this time, the console will output the merged configuration content, and copy the configuration content to overwrite the original $HOME/.kube/config.

3. Connect

  • View cluster information: kubectl config view, the names of the two clusters in this example are admin-cluster.local,kubernetes-admin@kubernetes

  • Connect to the cluster:

    kubectl --context admin-cluster.local get nodes  
    

Here is admin-cluster.localthe attribute in the configfile , which can be seen from the command.contexts.context.namekubectl config view

4. Set default

  • View the current default cluster:kubectl config current-context

  • Modify the current default cluster:kubectl config use-context kubernetes-admin@kubernetes

 

 

4. Source address

http://www.wisely.top/2018/03/06/kubectl-multiple-clusters/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326174143&siteId=291194637