Cloud Native 4 min read

Managing Multiple Kubernetes Clusters on One Node with kubeconfig

This guide explains how to simulate and maintain two separate Kubernetes clusters on a single node by configuring kubeconfig files, adding clusters, users, and contexts, and switching between them to improve DevOps workflow efficiency.

Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
Managing Multiple Kubernetes Clusters on One Node with kubeconfig

Simulating Two Kubernetes Clusters

First, create two independent clusters on the same physical host. The first cluster shows nodes k8smaster (control plane) and k8slave (worker) with IPs 192.168.40.180 and 192.168.40.181. The second cluster has k8smaster2 and k8slave2 with IPs 192.168.40.185 and 192.168.40.186, both running Kubernetes v1.23.1.

Viewing kubeconfig Files

Use kubectl config view or inspect /root/.kube/config to see the current configuration. Example output for the first cluster includes:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://192.168.40.180:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

The second cluster’s config is similar, with the server address changed to https://192.168.40.185:6443.

Adding the Second Cluster to the First Node’s kubeconfig

Add the cluster definition :

kubectl config set-cluster k8smaster2 --server=https://192.168.40.185:6443 --insecure-skip-tls-verify=true

Create a token for authentication (optional, shown for completeness): kubeadm token create --print-join-command Add user credentials :

kubectl config set-credentials k8smaster2-user --token=clknqa.km25oi82urcuja9u

Create a context linking the new cluster and user :

kubectl config set-context k8smaster2-context --cluster=k8smaster2 --user=k8smaster2-user

Switch to the new context to operate the second cluster: kubectl config use-context k8smaster2-context After these steps, the single node k8smaster can manage both k8smaster and k8smaster2 clusters by switching contexts. The same procedure can be repeated to add additional clusters, each accessed via its own context, thereby streamlining multi‑cluster management without violating DevOps principles.

cloud-nativeKubernetesDevOpsMulti-Clusterkubeconfig
Full-Stack DevOps & Kubernetes
Written by

Full-Stack DevOps & Kubernetes

Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.