kubectl-xctx

command module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 10 Imported by: 0

README

kubectl-xctx

CI Release License

A kubectl plugin to execute commands across multiple Kubernetes contexts matching a regular expression.

Install via krew

kubectl krew index add be0x74a https://github.com/be0x74a/krew-index
kubectl krew install be0x74a/xctx

Or directly from the manifest:

kubectl krew install --manifest-url=https://raw.githubusercontent.com/be0x74a/krew-index/main/plugins/xctx.yaml

Usage

kubectl xctx [flags] <pattern> <kubectl args...>

xctx flags must come before the pattern. Everything after the pattern is passed directly to kubectl.

Flags
Flag Short Default Description
--parallel -p false Run across all contexts concurrently
--list -l false List matching contexts without executing
--timeout -t 0 Per-context timeout (e.g. 10s, 1m). 0 = no timeout
--fail-fast false Stop after first failure (sequential mode only)
--header ### Context: {context} Header template. Use {context} as placeholder, "" to suppress
--version Print version
Examples
# Get pods in all contexts matching "prod"
kubectl xctx "prod" get pods

# Get pods in a specific namespace
kubectl xctx "prod" get pods -n kube-system

# Get nodes across staging and dev contexts, in parallel
kubectl xctx --parallel "staging|dev" get nodes

# List which contexts would be selected
kubectl xctx --list "prod"

# Run with a per-context timeout (skip unreachable clusters)
kubectl xctx --timeout 10s "." get pods -n kube-system

# Stop immediately on first failure
kubectl xctx --fail-fast "prod" apply -f deployment.yaml

# Suppress headers (useful for piping)
kubectl xctx --header "" "prod" get pods -o json | jq .
Output

Each context's output is grouped under a labeled header:

### Context: prod-us-east-1
NAME                    READY   STATUS    RESTARTS   AGE
my-app-abc123-xyz       1/1     Running   0          2d

### Context: prod-eu-west-1
NAME                    READY   STATUS    RESTARTS   AGE
my-app-def456-uvw       1/1     Running   0          2d

Build from source

git clone https://github.com/be0x74a/kubectl-xctx
cd kubectl-xctx
go build -o kubectl-xctx .

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL