Indexes and selection
Every kx get numbers the rows of the listing it prints, starting at 1, in the order kubectl returned them.
Those numbers are what the rest of kx takes.
kx get pods
kx describe 2The numbering is not a naming scheme and it is not stable across listings — it is a handle on the listing on your screen. List something else and the numbers mean something else. State and history covers exactly what “the listing on your screen” resolves to.
Several at once
Most commands are variadic. Space-separated indexes are taken in the order you gave them:
kx describe 1 3 5
kx events 2 4
kx yaml 1 2Ranges
A run of consecutive indexes can be written as a range instead of listed out.
Ranges walk in either direction, so 5..2 is as valid as 2..5 and does the work in that order.
kx delete 3..7Either end can be left open, and the open end means the listing’s own end:
kx describe ..3 # rows 1, 2, 3
kx describe 5.. # row 5 to the last rowRanges and single indexes mix freely — kx delete 1 2..4 7.. is one command.
An index named twice is one resource: overlapping ranges like 1..3 2..4 act on 1, 2, 3 and 4, each once.
A range is trimmed to the listing rather than refused for overshooting it.
On a 14-row listing 13..20 acts on rows 13 and 14, the same two 13.. reaches — a range names a span, and what you get is the part of it that exists.
A range entirely past the end is refused, because acting on nothing while appearing to succeed is worse than saying so:
kx describe 13..20 # rows 13 and 14, on a 14-row listing
kx describe 20..30 # ✗ '20..30' starts past the current listing (14 items)An index you type out is still taken literally: kx delete 13 99 refuses the whole batch rather than deleting 13, because a delete cannot be undone and a number you wrote yourself is not a gesture at a span.
Naming a resource directly
When you already know the name, there is no listing to count rows in. Every command that takes an index also takes the resource as kubectl spells it, kind/name:
kx diag deploy/api -n prod
kx logs deploy/api --context staging
kx tree sts/db
kx rollout restart deploy/api -n prod
kx mark api deploy/api -n prodThe namespace and cluster come from -n and --context as kubectl’s would, defaulting to the kubeconfig’s current ones.
That is the one way kind/name differs from an index, which carries both from the listing it was counted in and so refuses those flags.
A sweep refuses --context, since its rows would be numbered into this cluster’s history, and a kx tree of another cluster prints its walk unnumbered for the same reason.
A mark taken with --context is recorded against that context, so spending it from another one is refused as any mark’s is.
On a line that also holds an index or a mark, they are refused for the same reason.
Nothing is saved and no listing is needed, so a name from an alert, a teammate or another tool goes straight to kx diag.
The k9s plugin pack is built on it, handing the row under k9s’s cursor to kx this way.
Pinning it with kx mark checks the cluster first, so a typo fails there rather than at every command that spends the mark.
The one exception is kx cp, where kubectl already reads ns/pod:path as a namespace and a Pod, so its paths take an index or a mark.
Dropping the get
A first word that names a kind is treated as kx get <kind>:
kx pods
kx deploy -n kube-system
kx svc -m apikubectl’s own shorthands work — po, deploy, svc, sts, ds, cm and the rest.
So do CRDs: their short name, kind, or plural, resolved from kubectl’s on-disk API-discovery cache, so kx never calls the API server just to decide whether a word is a kind.
Registered commands always win.
Typing kx ns 3 switches namespace rather than listing namespaces, because ns is a command; only a spelling that matches no command reaches the kind shorthand.
A spelling that is neither a command nor a known kind still falls through to kx get <resource>, so kubectl gets the last word on whether it exists.
An integer after a kind relists just that row:
kx po 3Filtering
The --match/-m flag filters rows by case-insensitive name substring, after kubectl has returned them:
kx pods -m apiEverything kx doesn’t recognize is passed through to kubectl untouched — label selectors, field selectors, output formats, -n:
kx pods -n prod -l app=web
kx pods --field-selector status.phase=RunningOutput formats such as -o json pass through too, but there is no table to number in that output, so nothing is indexed.
The command prints what kubectl printed, and the listing you already had stays current — the numbers on screen before it still resolve.
Resources with no namespace
Some kinds do not live in one — Nodes, PersistentVolumes, StorageClasses, ClusterRoles, CRDs, and Namespaces themselves. Their listings record no namespace, and the caption leaves the segment out rather than naming whichever one you happened to be standing in:
Nodes · 1 itemnot Nodes · prod · 1 item.
The commands that resolve those indexes need nothing extra — kubectl ignores -n for a cluster-scoped resource — but a scope printed back at you should be one the resource actually has.
Kinds kx cannot place — a CRD missing from the cluster’s discovery data — keep a namespace rather than having one stripped on a guess. Being wrong about a caption is cheaper than resolving every index into the wrong place.
Every namespace
A listing made with -A is indexed like any other.
Each row records the namespace it came from, so an index reaches a resource in a namespace you aren’t currently in, and two Pods sharing a name in different namespaces each keep their own number.
kx get pods -A
kx logs 7 # reaches whichever namespace row 7 came fromThe listing gains a NAMESPACE column beside the numbers so you can see which is which.
Watching
The --watch/-w flag redraws the table live as resources are added, changed and removed, instead of printing one that is out of date the moment it lands:
kx get pods --watchEach row is numbered the first time it appears and keeps that index while the watch runs.
A row that changes, or moves under --sort, is still the number it was.
A deleted row’s index is never given to another resource, and a Pod recreated under the same name gets its old index back.
The watch saves its rows as your current listing within about a second of numbering a new one, so kx describe 3 in another terminal reaches the row drawn as 3.
If you list something else in the meantime, that listing stays current: within a second the watch drops its numbers, and its footer says another listing is now current.
Using the index of a row that has since been deleted does the same, since kx refreshes the listing with the plain kx get, without --watch, and the footer says a rerun renumbered the rows.
So does kx state drop --all, whose footer says the saved listings were cleared.
A watch numbers at most 1,000 rows; after that, new rows are drawn without a number, and no number already given changes.
A watch with more rows than the terminal has lines draws the first ones that fit and counts the rest under them; the rows it leaves out are still numbered and saved, so their indexes work as usual.
The numbers are also only drawn on a terminal: piped, a watch prints nothing to number.
If kx can’t read or write its state file, the watch keeps running without numbers.
A watch with --context or another cluster flag is drawn unnumbered, as that cluster’s listings are.
With a non-tabular output format, or with --no-headers, kx streams kubectl’s own watch output straight through rather than trying to redraw it, and numbers nothing.
When an index has gone stale
Resources get deleted. When a command fails because the resource behind an index is gone, kx runs the command that produced the listing again and prints a fresh one, so there are usable numbers on the screen rather than an error and a dead end. The failure is reported first — the refresh is the recovery, not a retry of what you asked for.
Each listing comes back as it was made.
A kx top listing is a usage table again, a kx diag sweep is swept again with the same scope, window and -m term, and a kx tree is walked again.
The refresh only ever prints the table, even when the listing was first sent to a browser or a script.
If the listing cannot be made again — a tree whose root is the resource that went, say — kx names the command to run instead.
A command whose output a script reads is not refreshed.
Under --json, or a kubectl -o format other than a table, kx reports the failure and the command to run on stderr, so nothing reaches stdout but the output that was asked for.