Skip to main content
kx — kubectl, indexed.

kubectl, indexed

PyPI version Python 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

pip install kx-cli

Usage

List resources

kx get <resource> [--match|-m <substring>] [kubectl flags...]

Fetches resources and assigns index numbers. Any extra flags (e.g. -n <namespace>, -A) are passed through to kubectl. Use --match/-m to filter results by name (substring, case-insensitive).

$ kx get pods
X  NAME                          READY  STATUS   RESTARTS  AGE
1  api-7d9f4b8c6-xkp2q           1/1    Running  0         2d
2  worker-6c8b5f7d9-mnt4r        1/1    Running  3         5h
3  postgres-0                    1/1    Running  0         12d

All subsequent commands reference resources by their X index from the last kx get.

Commands

Command Description
kx get <resource> [--match/-m text] [kubectl flags...] List resources and assign index numbers for use with other commands.
kx describe <indexes>... [kubectl flags...] Show full kubectl describe output for one or more indexed resources.
kx events <indexes>... 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 <indexes>... [--selector/-s] Show labels for one or more indexed resources; --selector formats output as a label selector.
kx yaml <indexes>... [--show text] Print the raw YAML manifest for one or more indexed resources; --show filters to specific top-level fields.
kx delete <indexes>... [--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> [<cmd>...] [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; --index assigns indexes to tree nodes.
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 port-forward <index> <port> [kubectl flags...] Forward a local port to an indexed resource (Pod, Deployment, ReplicaSet, StatefulSet, DaemonSet, Service).
kx namespace <index> Switch to an indexed namespace; alias: kx ns (run kx get namespaces first).
kx state [<position>] [--all/-a] Show current state, jump to a history position, or list all entries with --all.
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.

Example workflow

# list deployments, pick index 2
kx get deployments
kx describe 2

# check events on that deployment
kx events 2

# drill into a pod
kx get pods
kx logs 1
kx exec 1            # opens bash/sh
kx exec 1 -- env     # run a specific command

# forward local port 8080 to port 80 on a service
kx get services
kx port-forward 2 8080:80

# navigate history after multiple gets
kx get pods
kx get deployments
kx logs 1            # logs from pod index 1
kx state --all       # review full history

# clean up
kx delete 3

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 always resolve against the entry at the cursor.

$ kx get pods          # saves a new entry, cursor advances
$ kx get deployments   # saves another entry, cursor advances
$ kx logs 1            # resolves index 1 from the pods result
$ kx state --all       # lists all history entries and the current position

Use kx state <position> to jump directly to any history entry, and kx drop <position> to remove one.

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

Run the CLI directly:

python -m kx.main --help

Download files

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

Source Distribution

kx_cli-0.0.5.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

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

kx_cli-0.0.5-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file kx_cli-0.0.5.tar.gz.

File metadata

  • Download URL: kx_cli-0.0.5.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kx_cli-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3f750ccc34015b81ddd954f2a7013f2ad68b1586ed4a12a688d2908b7a010b4c
MD5 0ba80ce346dc3d3de7ced01e1d79c3d8
BLAKE2b-256 8180c1238dadf1bedd958e38f60db8ccdd67183052e905bc08491e6cbaea9877

See more details on using hashes here.

File details

Details for the file kx_cli-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: kx_cli-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kx_cli-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 beea960b695b03548fe5081d447e0b8bfa6e051bf8981e03943880379671716f
MD5 0c8ea8ec544ac7de68dc3886c5926151
BLAKE2b-256 b0a1760c09cbbffd3197ae7b62b5ebf9feeb1bac84ad63aff1d1e339fb7a00b4

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