Back to Blog

Tutorialยท

How to list resources such as Pods from multiple clusters

Learn how to effectively work with multiple clusters by listing resources from multiple clusters simultaneously

Introduction

When working with multiple Kubernetes clusters, it's often useful to be able to query resources from multiple clusters at once. This can help you troubleshoot issues, monitor performance, and gain insights into how your applications are behaving across all clusters.

In this blog post, we'll explore a few different options on how you can work with multiple cluster effectivelly. We'll start with a desktop application for those who prefer a GUI interface, and then look at kubectl and other CLI tools.

Ready? Let's get started!

Using Aptakube

Aptakube is the first GUI tool built from the ground up to work with multiple Kubernetes clusters. It's a desktop application that runs on Windows, macOS, and Linux.

Screenshot of Aptakube demonstrating its multi-cluster functionality by listing pods from 2 clusters in a single view.

The screenshot above is a great example of what to expect from Aptakube. It's the equivilant of running kubectl get pods on 2 clusters and then aggregating the results in a single view. You can see the cluster name, namespace, pod name, status, metrics and much more The same information is also available for all other resources such as deployments, services, ingresses, as well as custom resources.

Aptakube can connect to any Kubernetes clusters, regardless of where they are hosted, be it on-premises or in the cloud. There is nothing to install on clusters, Aptakube is basically a GUI for kubectl that runs on your desktop and aggregate data from multiple clusters.

This functionality really shines for teams that have applications deployed across multiple clouds or regions. It allows you to quickly see what's going on in each cluster without having to switch between different tools or log into each cluster individually.

Interested in learning more about what you can do with Aptakube? Take a look at all the other features.

Using Kubectl

By default kubectl only works with a single cluster at a time. While you could run kubectl get pods on each cluster individually and then aggregate the results, this is not very efficient and doesn't scale well.

Fortunately kubectl has built-in support for plugins and guess what? There's a plugin for this! It's called kubectl-foreach and it does exactly what you would expect: it runs a command on each cluster in your kubeconfig file.

You can install it with kubectl krew install foreach and then start using it right away. For example, to list pods from all clusters, you would run:

k foreach -- get pods -A

This will essentially loop through all clusters configured in your KUBECONFIG and run the get pods -A command on each one. The output will be aggregated and displayed in your terminal.

Example of kubectl-foreach output

As you'd expect, this can be used with any kubectl command, not just get pods.

You can also select which clusters you want to run this command on, for example:

kubectl foreach prod-eu prod-sa -- get pods

There's a lot more options available, so make sure to check out the kubectl-foreach repository for some more examples.

Guilherme Oenning
Guilherme Oenning@goenning
Tired of using Kubectl? ๐Ÿ˜“

Give Aptakube a go โ€” a modern, lightweight Kubernetes interface.

Screenshot of Aptakube showing a list of pods from 2 clusters in a single view