Skip to navigation

Inspect Workloads with the CLI

View as MarkdownOpen in Claude

The kli CLI shows which workloads run in a cluster and how each one is structured. It reads every workload through a definition, so the same commands work for any workload type that a definition covers. The CLI is read-only. It does not change workloads in the cluster.

CommandWhat it does
kli getLists the workloads of one type, or of every type, with a normalized phase.
kli describeShows one workload as a tree of components with its pods, phase, and requested resources.
kli definitionsLists the definitions that kli understands, and exports them.
kli validateChecks a definition file before you apply it.

Prerequisites

  • kli installed. For more information, refer to Installation.
  • For kli get and for kli describe on a live workload, a kubeconfig with read access to the workloads that you want to see.

The kli definitions and kli validate commands, and kli describe -f, do not need a cluster. Without a reachable cluster, they use the built-in catalog only.

Options in newer builds

The --catalog-experimental-definitions option, the --no-headers option, and -o wide for kli definitions are available in CLI builds after v0.3.0.

Connect to a Cluster

kli reads your kubeconfig the same way that kubectl does. It accepts the same connection flags, including --kubeconfig, --context, and -n or --namespace. For example, to list the JobSets in a namespace of another context, run the following command:

kli get jobsets --context <context> -n <namespace>

If the Karta Operator is not installed, the commands print the warning the kartas.run.ai CRD is not installed; showing built-in definitions only. It means that the cluster has no custom definitions, and you can ignore it.

List Workloads

To list the workloads of one type, run kli get with the type. The type match is lenient. It is not case-sensitive, and it accepts the singular, the plural, and the kubectl short names.

kli get jobset
NAME NAMESPACE PHASE AGE
my-training default Running 26s

The phase comes from the workload spec, so the output lists no pods. To list one workload, add its name, as in kli get jobset my-training or kli get jobset/my-training.

The following options narrow or extend the list:

OptionWhat it doesExample
--all-typesLists the top-level workloads of every type that a definition covers, with a TYPE column.kli get --all-types --phase Running
--phaseKeeps only the workloads in a phase. Repeat the option for more than one phase.kli get jobset --phase Degraded --phase Failed
-l, --selectorKeeps only the workloads that match a label selector on the workload.kli get jobset -l team=nlp
-o wideAdds an ORIGIN column that shows where the definition came from, the catalog or the cluster.kli get jobset -o wide
--no-headersOmits the header row of the table. It has no effect on JSON or YAML output.kli get jobset --no-headers

The phase is one of Undefined, Initializing, Running, Completed, Failed, Degraded, Suspending, Suspended, and Resuming.

Describe a Workload

To see the structure of one workload, run kli describe with its type and name:

kli describe jobset/my-training

The two-token form kli describe jobset my-training works as well. The output shows the following:

  • The component tree, with each pod placed under the component whose role it plays.
  • The normalized phase.
  • The resources that each component requests, and their total.

For a complete output, refer to the CLI quickstart.

A large workload can have many pods and components. To keep the output short, set a limit. When you set a limit, the output shows the unhealthy pods and components first:

OptionWhat it does
--pod-limit <n>Shows at most n pod rows for each component.
--component-limit <n>Shows at most n components under each parent.

Both options apply to the table output only.

Preview a Manifest Before You Submit It

To see how a workload would look before you submit it, run kli describe with -f and a manifest. Use - to read the manifest from standard input. The command needs no cluster, and it does not accept a type or a name.

kli describe -f jobset.yaml

The following output is for the JobSet manifest in the CLI quickstart:

JobSet/my-training namespace: <none> definition: jobset-x-k8s-io-jobset-v1alpha2 (catalog)
(file mode: no live status)
`-- replicatedjob replicas: 3
|-- leader replicas: 1
`-- workers replicas: 2
Resources:
COMPONENT REPLICAS GPU CPU MEMORY
leader 1 0 100m 64Mi
workers 2 0 400m 256Mi
TOTAL 3 0 500m 320Mi

The structure and the desired scale are real. The pods and the live status are absent, because the workload does not exist yet.

kli finds the definition for the manifest in the built-in catalog and in the cluster, if it can reach one. It does not read a definition from a local file. To preview a manifest with a definition that you wrote, apply the definition to the cluster first. For more information, refer to Define a Workload Type.

List and Export Definitions

To list every definition that kli understands, run the following command. The list merges the built-in catalog with the definitions in the cluster. A definition in the cluster overrides a catalog definition for the same type, and it is listed once, with the origin cluster.

kli definitions

The following options narrow the list or change what it shows:

OptionWhat it doesExample
NAMEShows one definition, by the name in the list.kli definitions kubeflow-org-pytorchjob-v1
--group, --kind, --versionShow the definitions that cover one workload type. --kind needs --group, and --version needs --kind.kli definitions --group jobset.x-k8s.io --kind JobSet
--component-limit <n>Lists at most n child components for each definition. The default is 3. Use 0 to list all of them.kli definitions --component-limit 0
-o wideAdds an APIVERSION column.kli definitions -o wide
-o yaml or -o jsonPrints the definitions themselves, under an items key.kli definitions -o yaml
--no-headersOmits the header row of the table. It has no effect on JSON or YAML output.kli definitions --no-headers

When you name a definition, the YAML and JSON output contains that definition alone, so you can apply it or validate it as it is. For example, the following command validates a catalog definition:

kli definitions kubeflow-org-pytorchjob-v1 -o yaml | kli validate -

To validate a definition that you wrote, refer to Define a Workload Type.

Include Experimental Definitions

A definition with spec.experimental: true is excluded by default. The exclusion applies to the definitions in the built-in catalog and to the definitions in the cluster. It covers listings, workload resolution, kli describe -f, kli get --all-types, and shell completion. The Kueue Workload definition is an example.

To include experimental definitions, use the --catalog-experimental-definitions option:

kli definitions --catalog-experimental-definitions
kli get workload --catalog-experimental-definitions

To save the preference, set the KARTA_CATALOG_EXPERIMENTAL_DEFINITIONS=true environment variable, or add catalog-experimental-definitions: true to the config file. An explicit option takes precedence over the environment variable, the environment variable takes precedence over the config file, and the config file takes precedence over the default. To turn off a saved opt-in for one command, use --catalog-experimental-definitions=false.

Naming an experimental definition or workload type still requires the opt-in. An excluded definition in the cluster does not override a stable definition in the catalog.

Choose an Output Format

The -o or --output option sets the output format. Each command accepts the formats in the following table:

CommandFormats
kli gettable, wide, json, yaml
kli describetable, json, yaml
kli definitionstable, wide, json, yaml

Use json or yaml when a script or another tool reads the output.

To change the default format, set output in a config file, or set the KARTA_OUTPUT environment variable:

output: json

kli reads the config file from the first of the following locations that applies:

  1. The path in the --config option.
  2. The path in the KARTA_CONFIG environment variable.
  3. $HOME/.karta/config.yaml. This file is optional.

The config file accepts the output key and the catalog-experimental-definitions key. If the file has any other key, kli stops with an error. The -o option overrides KARTA_OUTPUT, and KARTA_OUTPUT overrides the config file. A command that does not support the configured format uses the table format instead.

Use kli in Scripts

When a command fails, kli prints a message that starts with error: and exits with a code that identifies the kind of failure:

Exit codeMeaning
1A general failure, such as an unreachable cluster or an authentication failure.
2An invalid flag value or argument.
3No workload of the requested type has the requested name.
4No definition covers the requested type.

The kli validate command uses its own exit codes. For more information, refer to Define a Workload Type.

Set Up Shell Completion

Completion fills in commands, workload types, workload names, definition names, and namespaces when you press Tab. Load the completion script from your shell rc file:

# ~/.zshrc (after compinit)
eval "$(kli completion zsh)"
# ~/.bashrc, or ~/.bash_profile on macOS (needs the bash-completion package)
eval "$(kli completion bash)"

To list the other shells and the setup details, run kli completion --help.

Install from a Clone

In a clone of the repository, the following make targets build kli, install it, and add its completion to your bash or zsh rc file:

TargetWhat it does
make install-cliBuilds kli, copies it to /usr/local/bin, and loads its completion.
make uninstall-cliRemoves kli from /usr/local/bin and its completion.
make install-cli-localDoes the same as install-cli with $HOME/.local/bin, which needs no root.
make uninstall-cli-localDoes the same as uninstall-cli with $HOME/.local/bin.
make install-cli-completionBuilds kli into the ./bin/ directory of the repository and loads only its completion.
make install-cli-completion-localDoes the same as install-cli-completion, and prefers the kli in $HOME/.local/bin.
make uninstall-cli-completionRemoves the completion.

To install to another directory, set BINDIR or PREFIX, for example make install-cli BINDIR=/opt/tools/bin.

The rc file entry loads completion from the installed kli when it exists. Otherwise, it falls back to ./bin/kli in the repository. If you installed kli with make install-cli-local, use make install-cli-completion-local, so that the entry checks $HOME/.local/bin.

Next Steps