Inspect Workloads with the CLI
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.
Prerequisites
kliinstalled. For more information, refer to Installation.- For
kli getand forkli describeon 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.
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:
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.
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:
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:
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:
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.
The following output is for the JobSet manifest in the CLI quickstart:
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.
The following options narrow the list or change what it shows:
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:
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:
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:
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:
kli reads the config file from the first of the following locations that applies:
- The path in the
--configoption. - The path in the
KARTA_CONFIGenvironment variable. $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:
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:
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:
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
- To write your own definition, refer to Define a Workload Type.
- For every command, option, and exit code, refer to the CLI Command Reference.
- To fix an error that
kli validatereports, refer to Troubleshoot Definitions.