Skip to main content
This guide walks through running a simple Katib Experiment CR that launches a few trials using a BusyBox job and reports a single metric called score. Katib will attempt to maximize this metric across trials. Prerequisite: Katib must be installed so the Experiment CRD and controllers are available in your cluster. The controllers interpret kind: Experiment and create Trial resources according to the Experiment spec.
Ensure Katib (CRDs and controllers) is installed before applying Experiment resources. If you want Katib to collect metrics by injecting a metrics-collector into trial pods, label the target namespace for metrics-collector injection (see the namespace section below).

Experiment YAML (single-file example)

Below is the complete Experiment YAML used in this demo. It defines:
  • a single integer parameter x (feasible space 1–10),
  • the random algorithm,
  • up to 3 trials with 1 running at a time,
  • a trial template implemented as a Kubernetes Job that runs BusyBox and echoes score, which Katib collects.

Key fields explained

Create or reuse the namespace

Create the kubeflow namespace if it doesn’t exist:
List namespaces:
Example output:
If you want Katib to inject the metrics collector into trial pods in the kubeflow namespace (so the collector can scrape stdout), label the namespace:
Expected output after labeling:

Apply the experiment

Save the YAML above to experiment.yaml and apply it:
Example response (resource unchanged):
List Experiments in the namespace:
Example output:
Watch Trials as they are created:

What a trial does

Each Trial uses the trial template with a sampled value for x. In this demo the trial container runs:
  • Trying x=<value> — informational
  • score=<value> — metric output Katib collects
The metric lines are the only thing Katib needs to parse an objective value. For example, if a trial runs with x=7, the trial prints score=7 and Katib interprets that trial’s objective metric as 7. Because the objective is maximize, trials returning higher score are preferred. The trial command lines that emit the score:
(These lines appear in the args block of the trialSpec in the YAML above.)

Inspecting Katib components and UI

List Katib services in the kubeflow namespace to find the controller, DB manager, UI, and related components:
Example output:
Port-forward the Katib UI and open it in your browser:
Open: http://localhost:8080 The UI shows experiments, objectives, trial status, parameter values, and logs. In the screenshot below you can see the simple-katib-demo experiment listing objective, trials, parameters, and algorithm settings.
A computer screenshot showing a browser open to a Kubeflow Katib "Experiment details" page listing objective, trials, parameters, and algorithm settings. In the background is a code editor (VS Code) with an experiment.yaml file.
The controller also stores Experiment resource metadata and annotations (for example the last-applied configuration), which can be viewed in the UI or by running kubectl describe or kubectl get -o yaml on the Experiment resource. Example metadata snippet:

Troubleshooting tips

  • If Trials are not created, ensure the Katib controller is running and the Experiment CR was accepted (kubectl get events -n kubeflow).
  • If metrics are not being collected, confirm the metrics-collector injection label is set on the namespace (or use an external collector) and check trial pod logs for the score= output.
  • Use kubectl logs <trial-pod> -n kubeflow to view the BusyBox output from a trial to confirm it printed score=<value>.

Summary

  • Katib experiments are defined by the Experiment CRD. Install Katib and its CRDs first.
  • This demo uses a BusyBox trial that emits score=<value>; Katib collects that output and optimizes score.
  • Use kubectl to create namespaces, apply the Experiment, and watch Trials. Port-forward katib-ui to inspect experiments and metrics in the UI.
  • The trial template and the printed metric lines are the core pieces — whatever Katib can parse as the objective metric is what it will optimize.

Watch Video

Practice Lab