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 areadmin-cluster.local
,kubernetes-admin@kubernetes
-
Connect to the cluster:
kubectl --context admin-cluster.local get nodes
Here is
admin-cluster.local
the attribute in theconfig
file , which can be seen from the command.contexts.context.name
kubectl 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