Skip to main content
kx — kubectl, indexed.

kubectl, indexed

PyPI version License CI

kx is a kubectl wrapper that adds index-based resource selection. Run kx get <resource> once, then reference any result by number instead of typing full resource names.

kx demo

Install

Requires kubectl on your PATH. Every install path below delivers the same prebuilt binary — no Python runtime, no dependencies.

With uv (recommended):

uv tool install kx-cli

With pipx:

pipx install kx-cli

With pip:

pip install kx-cli

As a kubectl plugin via krew, where kx is published as idx:

kubectl krew install idx
alias kx="kubectl idx"

Standalone binaries for linux, macOS and Windows (amd64/arm64) are attached to each GitHub Release, with checksums in SHA256SUMS.

On macOS, the first run of a freshly installed krew plugin or standalone binary takes a few seconds while Gatekeeper scans the binary; later runs are unaffected until the next install. Get it over with up front:

kx --version >/dev/null

Or try it without installing (the package is kx-cli, the command is kx):

uvx --from kx-cli kx get pods
pipx run --spec kx-cli kx get pods

Usage

kx get <resource> fetches resources and assigns each row an index; every other command takes those indexes. Extra flags pass through to kubectl (-n <namespace>, selectors, ...), and --match/-m filters rows by name substring. All-namespace listings (-A) are display-only — names aren't unique across namespaces.

Known kinds can drop the get: kx pods, kx deploy -n kube-system, kx svc --match api — kubectl shorthands (po, deploy, svc, sts, ...) included. An integer after a kind relists just that index: kx po 3. CRDs and other resource types still use kx get <resource>.

Global flags: --no-color disables styled output, -v/--version prints the installed version, and -h/--help on any command shows usage, examples, and aliases.

Commands

Command Description
kx get <resource> [<index>...] [--decode] [--key/-k str] [--match/-m str] [--yes/-y] [kubectl flags...] List resources and assign index numbers for use with other commands; shorthand: kx (e.g. kx pods, kx po 3).
kx secret [<index>...] [--decode] [--key/-k str] [--match/-m str] [--yes/-y] [kubectl flags...] List Secrets like kx get, or show an indexed Secret's data with --decode; alias: kx secrets.
kx top [--match/-m str] [--no-limits] [kubectl flags...] List CPU/memory usage for pods in the current namespace and assign index numbers, like kx get; shows usage as a percent of each pod's resource limits unless --no-limits.
kx describe <index>... [kubectl flags...] Show full kubectl describe output for one or more indexed resources.
kx events <index>... Show Kubernetes events for one or more indexed resources.
kx logs <index>... [kubectl flags...] Stream logs for an indexed resource; aggregates across pods for Deployments, StatefulSets, DaemonSets, and Services.
kx labels <index>... [--selector/-s] Show labels for one or more indexed resources; --selector formats output as a label selector.
kx annotations <index>... Show annotations for one or more indexed resources.
kx label <index> [<key=value>...] [--overwrite] [--remove str] Set or remove labels on an indexed resource.
kx annotate <index> [<key=value>...] [--overwrite] [--remove str] Set or remove annotations on an indexed resource.
kx yaml <index>... [--show str] Print the raw YAML manifest for one or more indexed resources; --show filters to specific top-level fields.
kx delete <index>... [--yes/-y] Delete one or more indexed resources (prompts for confirmation unless --yes).
kx edit <index> [kubectl flags...] Open an indexed resource in your editor via kubectl edit.
kx exec <index> [<command>...] [kubectl flags...] Open an interactive shell in an indexed pod (bash, falling back to sh).
kx tree [<index>] [--index/-i] Show the ownership graph for an indexed resource, or the whole current namespace when no index is given; --index assigns indexes to tree nodes. A Namespace index graphs that namespace.
kx rollout <action> <index> Run a rollout action (status, restart, pause, resume, history, undo) on a Deployment, StatefulSet, or DaemonSet.
kx scale <index> <replicas> Scale an indexed Deployment, StatefulSet, or ReplicaSet to a given replica count.
kx scan [<index>] [--all-namespaces/-A] [--engine str] [--full] [--html] [--namespace/-n str] [--no-open] [--port int] [scanner flags...] Scan the unique container images of an indexed workload for vulnerabilities, or a whole namespace when no index is given (-n to pick one, -A for every namespace); prints a severity summary table by default, or the raw scanner output with --full. Requires the Docker Scout CLI plugin (https://docs.docker.com/scout/).
kx port-forward <index> <port> [kubectl flags...] Forward a local port to an indexed resource (Pod, Deployment, ReplicaSet, StatefulSet, DaemonSet, Service).
kx diagnostic [<index>] [--all-namespaces/-A] [--html] [--namespace/-n str] [--no-open] [--port int] Diagnose an indexed Deployment, StatefulSet, DaemonSet, Job, CronJob, Service, PersistentVolumeClaim, or Pod, or triage a whole namespace when no index is given (-n to pick one, -A for every namespace); alias: kx diag.
kx namespace [<index>] List namespaces, or switch to an indexed one; alias: kx ns.
kx context [<index>] List kubeconfig contexts, or switch to an indexed one; alias: kx contexts.
kx state [<position>] [--all/-a] [--targets/-t] Show current state, jump to a history position, list all entries with --all, or expand the switch targets with --targets.
kx drop <position> Remove a history entry by position (shown in kx state --all).
kx back Navigate to the previous kx get result.
kx forward Navigate to the next kx get result.
kx theme [<name>] List available color themes or persist a choice by name or index.

Triage a namespace

Bare kx diag sweeps the current namespace — Deployments, StatefulSets, DaemonSets, Jobs, CronJobs, Services, and PersistentVolumeClaims, plus pods nothing owns — and prints a ranked table of what's unhealthy. Findings also draw on live resource usage (kx top): a pod running hot against its memory limit is flagged as an OOMKill risk before it dies. The rows are indexed, so kx diag 1 or kx logs 2 drill straight in.

kx diag demo

kx diag <index> diagnoses a single resource: a verdict banner, a SUMMARY of findings (CrashLoopBackOff, image pull failures, OOMKills, unschedulable pods, stalled rollouts, missing Service endpoints, Pending PVCs, failed CronJob runs, usage near limits), a per-pod status table, recent log tails from broken containers, and warning events — one screen instead of four kubectl commands.

Read a Secret in plaintext

kx secret <index> --decode prints an indexed Secret's keys and values decoded, instead of the base64 kubectl returns. Values that aren't text show a <binary, N bytes> placeholder rather than garbling the table. --key/-k prints a single value raw — no banner, no wrapping — so it drops straight into a shell: export PGPASSWORD=$(kx secret 1 --decode -k password), or redirect a binary value to a file. Bare kx secret --decode decodes every Secret in the namespace in one call, -n included — it confirms first unless you pass --yes/-y, since that prints every credential in the namespace.

kx secret --decode demo

Scan images for vulnerabilities

kx scan <index> scans the unique container images of an indexed workload (init containers and CronJob job templates included); bare kx scan sweeps every workload in the namespace. Results come back as a severity summary, or the full per-image CVE report with --full. Requires Docker Scout.

kx scan demo

View reports in a browser

kx diag --html and kx scan --html render the same analysis as a page and open it in your browser as well as printing to the terminal; Ctrl-C stops the server. It binds 127.0.0.1 only, and nothing is written to disk — the report lives in memory for as long as the command runs.

The page is drawn in your active theme, so kx theme dracula restyles it too. Sweep rows expand into that resource's full report, and image rows expand into the CVEs behind their severity counts — detail the terminal has no room for. None of it costs an extra API or scanner call: both were already gathered to build the table you'd see without --html.

--port serves on a specific port instead of picking a free one, and --no-open skips launching a browser — the URL still prints, so you can open it yourself.

State

kx maintains a history of up to 10 kx get results in ~/.kx/state.json. A cursor tracks your current position; index-based commands resolve against the entry at the cursor. kx state --all lists the history, kx state <position> jumps to an entry, kx back/kx forward step through it, and kx drop <position> removes one.

Namespaces and contexts are kept separately, outside that history. kx ns and kx contexts each save their listing to their own slot, so kx ns 2 counts against the namespaces you last listed no matter what you have listed since — and switching namespaces, which is frequent, never pushes work out of the history. kx state --all summarizes those slots under the history table, and kx state --targets expands them to the indexed listings the switch commands read, so you can pick a number without re-listing.

To operate on a namespace rather than switch to it, list it like any other resource with kx get ns; that puts it in the history too, so kx describe <index> and kx label <index> work as usual. It refreshes the slot as well, so the two spellings never disagree about what index 2 means. A narrowed listing counts, though: after kx get ns -l team=platform, kx ns <index> indexes into those namespaces rather than all of them. Run kx ns to list them all again.

Configuration

kx reads ~/.kx/config.toml; environment variables override file settings.

Key Env var Default Description
max_history KX_MAX_HISTORY 10 Number of kx get results kept in history.
shells KX_SHELLS (comma-separated) ["bash", "sh"] Shell candidates for kx exec.
no_color KX_NO_COLOR false Disable styled output (same as --no-color).
theme KX_THEME "github-dark" Color theme for all output.

Styled output is emitted only when stdout is a terminal — piped or redirected output is plain text, so kx get pods | grep worker stays clean. The NO_COLOR convention is honored as well.

Themes

kx theme lists the available themes with a preview of each; kx theme <name|index> persists a choice to ~/.kx/config.toml.

kx theme demo

Prefab themes: github-dark (default), dracula, nord, gruvbox, solarized-dark, catppuccin-mocha, tokyo-night, rose-pine, mono, light (for light terminal backgrounds), and plain (no styling at all).

Development

Go, at the version pinned by the go directive in go.mod. Nothing else is required to build or run.

go build ./...

Run the CLI directly:

go run ./cmd/kx --help
go run ./cmd/kx get pods

Checks:

gofmt -l ./cmd ./internal ./tools   # must print nothing
go vet ./...
go test -race ./...

pre-commit run --all-files runs gofmt and go vet, and regenerates the command table above from the command tree — it fails if the table has drifted from the commands it documents. Tests are not in the hook; run them yourself.

The demo GIFs are rendered from VHS tapes — see demo/README.md for seeding the demo namespace and re-recording.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kx_cli-0.1.2-py3-none-win_arm64.whl (44.3 MB view details)

Uploaded Python 3Windows ARM64

kx_cli-0.1.2-py3-none-win_amd64.whl (47.8 MB view details)

Uploaded Python 3Windows x86-64

kx_cli-0.1.2-py3-none-musllinux_1_2_x86_64.whl (46.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

kx_cli-0.1.2-py3-none-musllinux_1_2_aarch64.whl (44.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

kx_cli-0.1.2-py3-none-manylinux_2_17_x86_64.whl (46.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

kx_cli-0.1.2-py3-none-manylinux_2_17_aarch64.whl (44.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

kx_cli-0.1.2-py3-none-macosx_11_0_arm64.whl (45.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

kx_cli-0.1.2-py3-none-macosx_10_9_x86_64.whl (47.6 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file kx_cli-0.1.2-py3-none-win_arm64.whl.

File metadata

  • Download URL: kx_cli-0.1.2-py3-none-win_arm64.whl
  • Upload date:
  • Size: 44.3 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for kx_cli-0.1.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 3e846f593a9f879b434958cbb7d4b0d8e3678b113520e0fbe6483511f78f3dd7
MD5 c345fe729803618890490494f6c07eaa
BLAKE2b-256 c10511b30b546821ea73c4702f4df7967e374c34d5e70876b1168e3d92e23816

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: kx_cli-0.1.2-py3-none-win_amd64.whl
  • Upload date:
  • Size: 47.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for kx_cli-0.1.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c2741999b0e6ba3d6564fbe5f58567b3e3c4906acacd1f818c4fd3240ffb810e
MD5 90e1170d123dacbbc816baafb301ad42
BLAKE2b-256 9d0d3445f32b1ef13e3c19b1e0d0121904ab3905411ce396252af2a419e4e7ee

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1a99fa36c0ad104ac7117c6ee1241d25cbdd7339dad6d00876a00e8910aa2f8b
MD5 45bc00e4dcfb778950a11cd4e98770d7
BLAKE2b-256 89fed33f470e8666e9108ec14eded896b18d70f7730e4dbf43604976bda639aa

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bceb6e119307443f395a110d5d6774b610fae48f291d5e53d5af0b30be833121
MD5 bfd3c5b03606b10105b4dcef552a0dfc
BLAKE2b-256 0ed2a02fd9f5726089caf076856802c07a585bc49ca01beea235c1942423cac6

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d15570b4496cd181e18f374efdd95a38362a192ebf15c68b917c42e7ac4e674e
MD5 f365cdf7e486b9cc631d1ce0546aabc1
BLAKE2b-256 bd05709e505918a41c45ef4f1aff352d1584a89f9babdcb7cd624df7886c4163

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 2c8111def5eb55378dacaaa56b77a834a36d0d26d55f70c24a4c8ac87dc05f10
MD5 49f014a11abc9cea7d0043bd6b3273e3
BLAKE2b-256 b249a488ce9f4d60e70d41b540af406312b76a45392a8efa9b6d789da8431726

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e60fc9b2d41e707977f2776b13586dd5e839b915d117d2ab5d1c3183d0234f8c
MD5 cc0bf3fc121f6a006c02e07593d00348
BLAKE2b-256 3fb5b62808791f26893c209e9abbac6759c0fda2a4e2d679d5b233375d117ce4

See more details on using hashes here.

File details

Details for the file kx_cli-0.1.2-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for kx_cli-0.1.2-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d668bc68d799411b8f4a06e6fe93983aab5378e08b8a10bb6ef66f4bddcd7b22
MD5 0157d93acd8b5395c91f9ab3430918a2
BLAKE2b-256 ea91da61eed99ee1881d544c1c8bc374b7276ce924afc55d4dec7a27718bf8bd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page