<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Diogo Vilela</title>
    <description>The latest articles on DEV Community by Diogo Vilela (@be0x74a).</description>
    <link>https://dev.to/be0x74a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3781730%2Fe6503c41-868a-42f9-b9ca-3592a55dd563.jpg</url>
      <title>DEV Community: Diogo Vilela</title>
      <link>https://dev.to/be0x74a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/be0x74a"/>
    <language>en</language>
    <item>
      <title>Managing Multiple Kubernetes Clusters Without Losing Your Mind</title>
      <dc:creator>Diogo Vilela</dc:creator>
      <pubDate>Thu, 19 Feb 2026 22:55:08 +0000</pubDate>
      <link>https://dev.to/be0x74a/managing-multiple-kubernetes-clusters-without-losing-your-mind-12ba</link>
      <guid>https://dev.to/be0x74a/managing-multiple-kubernetes-clusters-without-losing-your-mind-12ba</guid>
      <description>&lt;p&gt;If you work with Kubernetes in production, you probably don't have just one cluster. You might have regional replicas, a staging environment, a dev cluster, maybe a sandbox for experiments. Your kubeconfig has a dozen contexts and growing.&lt;/p&gt;

&lt;p&gt;And every time you need to check something across clusters, you do this dance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl config use-context prod-us-east-1
kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; backend
kubectl config use-context prod-eu-west-1
kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; backend
kubectl config use-context staging-us-east-1
kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; backend
&lt;span class="c"&gt;# ... you get the idea&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or maybe you've written a shell loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;ctx &lt;span class="k"&gt;in &lt;/span&gt;prod-us-east-1 prod-eu-west-1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"=== &lt;/span&gt;&lt;span class="nv"&gt;$ctx&lt;/span&gt;&lt;span class="s2"&gt; ==="&lt;/span&gt;
  kubectl &lt;span class="nt"&gt;--context&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ctx&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; get pods &lt;span class="nt"&gt;-n&lt;/span&gt; backend
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works until it doesn't — hardcoded cluster names, no parallelism, no error handling, no timeout for that one cluster with flaky networking. Every team ends up with their own version of this script.&lt;/p&gt;

&lt;h2&gt;
  
  
  A better way
&lt;/h2&gt;

&lt;p&gt;I built &lt;a href="https://github.com/be0x74a/kubectl-xctx" rel="noopener noreferrer"&gt;kubectl-xctx&lt;/a&gt; to solve this properly. It's a kubectl plugin that takes a regex pattern and runs any kubectl command across all matching contexts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl xctx &lt;span class="s2"&gt;"prod"&lt;/span&gt; get pods &lt;span class="nt"&gt;-n&lt;/span&gt; backend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is grouped per context with clear headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;### Context: prod-us-east-1
NAME                    READY   STATUS    RESTARTS   AGE
api-server-abc123       1/1     Running   0          3d
worker-def456           1/1     Running   0          3d

### Context: prod-eu-west-1
NAME                    READY   STATUS    RESTARTS   AGE
api-server-xyz789       1/1     Running   0          3d
worker-uvw012           1/1     Running   0          3d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What it can do
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Preview matching contexts&lt;/strong&gt; before running anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl xctx &lt;span class="nt"&gt;--list&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt;
&lt;span class="c"&gt;# prod-us-east-1&lt;/span&gt;
&lt;span class="c"&gt;# prod-eu-west-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run commands in parallel&lt;/strong&gt; when you don't want to wait for sequential execution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl xctx &lt;span class="nt"&gt;--parallel&lt;/span&gt; &lt;span class="s2"&gt;"staging|dev"&lt;/span&gt; get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set a per-context timeout&lt;/strong&gt; to skip unreachable clusters instead of hanging forever:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl xctx &lt;span class="nt"&gt;--timeout&lt;/span&gt; 10s &lt;span class="s2"&gt;"."&lt;/span&gt; get pods &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fail fast&lt;/strong&gt; on the first error (useful for apply/delete operations):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl xctx &lt;span class="nt"&gt;--fail-fast&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt; apply &lt;span class="nt"&gt;-f&lt;/span&gt; deployment.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Suppress or customize headers&lt;/strong&gt; for scripting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Pipe JSON output cleanly&lt;/span&gt;
kubectl xctx &lt;span class="nt"&gt;--header&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt; get pods &lt;span class="nt"&gt;-o&lt;/span&gt; json | jq &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Custom header format&lt;/span&gt;
kubectl xctx &lt;span class="nt"&gt;--header&lt;/span&gt; &lt;span class="s2"&gt;"=== {context} ==="&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt; get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Before and after
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Check pods across 4 prod clusters&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before: 4 commands, switching context each time&lt;/li&gt;
&lt;li&gt;After: &lt;code&gt;kubectl xctx "prod" get pods&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Get nodes from staging + dev&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before: shell loop with hardcoded context names&lt;/li&gt;
&lt;li&gt;After: &lt;code&gt;kubectl xctx "staging|dev" get nodes&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quick check across all clusters&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before: custom script, hope it works&lt;/li&gt;
&lt;li&gt;After: &lt;code&gt;kubectl xctx --parallel --timeout 10s "." get pods&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;See which contexts match a pattern&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before: &lt;code&gt;kubectl config get-contexts | grep prod&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After: &lt;code&gt;kubectl xctx --list "prod"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Via krew&lt;/strong&gt; (Kubernetes plugin manager):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl krew index add be0x74a https://github.com/be0x74a/krew-index
kubectl krew &lt;span class="nb"&gt;install &lt;/span&gt;be0x74a/xctx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or directly from the manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl krew &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--manifest-url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://raw.githubusercontent.com/be0x74a/krew-index/main/plugins/xctx.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Via Homebrew&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;be0x74a/tap/kubectl-xctx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;From source&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/be0x74a/kubectl-xctx
&lt;span class="nb"&gt;cd &lt;/span&gt;kubectl-xctx
go build &lt;span class="nt"&gt;-o&lt;/span&gt; kubectl-xctx &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's a single Go binary with no dependencies beyond kubectl itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The implementation is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reads your kubeconfig contexts via &lt;code&gt;kubectl config get-contexts -o name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Filters them against the regex you provide&lt;/li&gt;
&lt;li&gt;Runs &lt;code&gt;kubectl --context &amp;lt;name&amp;gt; &amp;lt;your args&amp;gt;&lt;/code&gt; for each match&lt;/li&gt;
&lt;li&gt;Groups output with labeled headers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In parallel mode, all contexts execute concurrently via goroutines, with results printed in order after all complete.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it out
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/be0x74a/kubectl-xctx" rel="noopener noreferrer"&gt;be0x74a/kubectl-xctx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you manage multiple clusters, give it a try. I'd love to hear what workflows it helps with — or what's missing.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>kubectl</category>
      <category>devops</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
