Cloud Native 3 min read

Effortlessly Manage Multiple Kubernetes Clusters with kubecm

Learn how to install kubecm, merge multiple kubeconfig files, list, switch, and delete cluster contexts, enabling streamlined, single‑file management of many Kubernetes clusters directly from the command line without manually editing the config file, and see visual cues for the active context.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Effortlessly Manage Multiple Kubernetes Clusters with kubecm

Background

Kubernetes provides the

kubectl

command‑line tool to operate clusters, using a

kubeconfig

file (default location

~/.kube/config

) for configuration. To manage multiple clusters with

kubectl

, you can add several cluster entries to the same

kubeconfig

by editing the file directly or running a series of

kubectl config

commands.

After a Kubernetes cluster is installed, a

kubeconfig

file is generated. To combine these files so that a single

kubeconfig

can manage many clusters, you can use the

kubecm

tool, which this article demonstrates.

Install kubecm

First, install

kubecm

on the machine that will manage multiple clusters. Refer to the official documentation for installation instructions.

Add credentials to kubeconfig with kubecm

Obtain the

kubeconfig

file for a cluster, rename it to the desired context name, and merge it into

~/.kube/config

with the following command:

<code>kubecm add -f &lt;file&gt;</code>
When prompted, choose True to overwrite the default kubeconfig file, then press Enter.

View cluster list

After adding clusters with

kubecm

, run

kubecm ls

to display the list of clusters in the

kubeconfig

. An asterisk marks the currently active cluster.

Switch cluster

To switch to another cluster, use

kubecm switch

for an interactive selection:

However, using

kubectx

for switching is still recommended.

Remove cluster

To delete a cluster, run

kubecm delete &lt;context&gt;

:

clicloud-nativeKuberneteskubeconfigkubecm
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

login 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.