Overview

7 Data analysis and preparation

This chapter argues that robust data preparation is the foundation of successful machine learning, then shows how to operationalize it with Kubeflow. It begins by addressing the realities of data analysis at scale—running close to large datasets while offering on-demand, interactive compute—and presents Kubeflow notebooks as the solution. Readers learn how to launch and tune notebook servers (images, resources, GPUs), work with workspace and data volumes, apply PodDefaults, affinity, and tolerations, and customize the Jupyter Web App menu. The chapter also explains how to build custom notebook images and fold them into CI/CD so experimentation mirrors deployment, improving reproducibility and version control.

The core pipeline concepts focus on how isolated components pass data in Kubeflow Pipelines v2. After demonstrating simple parameter passing, the chapter emphasizes artifact-based data movement for large datasets using strongly typed Input/Output artifacts (for example, Dataset, Model, Metrics, HTML, Markdown, and generic Artifact), along with practical guidance on dependency management via packages_to_install, base_image, and best practices like scoping imports inside component functions. It further introduces containerized Python components that prebuild dependencies into images (target_image) for faster, more reliable execution—bridging lightweight components and full container components—while maintaining clear interfaces and type safety.

Two end-to-end data preparation projects put these ideas into practice. For object detection (YOLOv8), the chapter covers formatting expectations, building components to download and unpack data, store assets in MinIO, split images and labels into train/validation/test, and validate outputs. For a movie recommender using the MovieLens 25M dataset, it adds tabular-specific steps: unzip, convert CSV to Parquet for efficiency, split datasets, upload to MinIO, and perform QA with pyarrow, all orchestrated as a Kubeflow pipeline executed from the UI or SDK. Along the way, it highlights caching choices, logging trade-offs, and resource controls, showing how well-structured components and typed artifacts yield reproducible, scalable, and observable data preparation workflows.

The mental map where we are now focusing the first step/component of our pipeline - data collection and preparation(3)
Click on New Notebook to launch a Kubeflow notebook
Image configuration options for name, namespace, image and resources
Configuration options for adding a workspace and data volumes to the notebook
Affinity and tolerations group configurations
Overview of the layers in a custom Kubeflow notebook image.
MIDV-500 dataset. Source: https://github.com/fcakyon/midv500
The Data Preparation Pipeline. First data is downloaded from a remote location, then it is split and two files are selected to pass through a sanity check.
The Pipelines screen lists all the uploaded pipelines and also lets you upload new pipelines.
Pipelines can either be zip files or YAML. In this case, we're selecting a YAML file.
After a successful upload, you can see the pipeline.
The Run details page is mostly populated automatically. You'll have to choose the experiment.
A completely executed Kubeflow pipeline. Seeing this gives us warm fuzzy feelings every time (and a sigh of relief).
Clicking each component reveals the side menu. Clicking on the logs tab lets you see all the output. If the component is running, the output is in real-time.
The pipeline we are going to build out in this section
The successfully run pipeline

Summary

  • ML workflows demand close proximity to datasets for processing while necessitating ad-hoc access to specialized resources like GPUs.
  • Kubeflow notebooks offer Jupyter-like interfaces within the same cluster as pipelines, ensuring environment consistency with deployment settings.
  • These notebooks streamline versioning and CI/CD practices by sharing base images and integrating into CI pipelines, simplifying management and ensuring robust controls.
  • Kubeflow components can be created using kfp.create_component_from_func.
  • Understanding the data passing rules in Kubeflow components, and the different scenarios for data passing between components, including the results for input and output of pipeline parameters and naming conventions like training _path and _file, are essential building Kubeflow components.
  • When building components using functions, import statements should be defined within the function definition. Third-party dependencies can be installed by specifying the packages_to_install parameter in kfp.create_component_from_func.
  • Combining these Kubeflow components form a Kubeflow pipeline, which is specified using the @dsl.pipeline decorator.
  • Once the pipeline is compiled, a YAML file is produced. This YAML file contains boilerplate code that not only contains the individual function definitions, but also code that handles argument parsing and serialization of input/output parameters.
  • The YAML file can be uploaded and executed from the Kubeflow UI or via the SDK. You can also check on the progress by viewing the real-time generated logs from the UI.
  • Leveraging Kubeflow components, this chapter outlines the assembly of a object detector pipeline, employing various steps from dataset download to splitting the dataset into train/test/validation.
  • It also outlines the assembly of a movie recommender system pipeline, employing various steps from dataset download to quality assurance checks.
  • Using parquet file storage and conversion techniques, the chapter demonstrates efficient data handling methods, including CSV to Parquet conversion and dataset splitting for model training.
  • Next chapter will work on creating the components and pipelines for training the object detection and movie recommender models. We will make use of the data from pipelines developed in this chapter and add some features to the data preparation components to reflect learnings we have from our training experiments.

FAQ

What problems do Kubeflow notebooks solve for data analysis and experimentation?Kubeflow notebooks provide familiar IDEs (Jupyter, VS Code, RStudio) inside your Kubeflow cluster, running close to the data. They make it easy to spin up and tear down powerful compute (CPU/GPU/TPU) on demand, keep environments reproducible by sharing base images with pipelines, and fit into CI/CD with versioned, custom images. This gives you interactive analysis that mirrors the deployment environment without bespoke infrastructure.
How do I launch a Kubeflow notebook and choose the right image and resources?From the Kubeflow UI, go to Notebooks → New Notebook. Pick the correct Kubernetes namespace (it controls quotas, mounts, and secrets), select a base image (or a custom image added by your admin), and set CPU/memory requests/limits. If you need accelerators, select GPUs/TPUs sparingly and ensure idle-stop policies are in place because these resources are expensive and exclusive while a notebook pod is running.
What’s the difference between a workspace volume and data volumes in notebooks?The workspace volume is automatically mounted (by default under /home/jovyan) and persists notebook files and configs across restarts. It is usually provisioned from the cluster’s default storage class when the notebook is created. Data volumes are pre-existing Persistent Volume Claims (PVCs) that you optionally mount for datasets. You can also reuse a pre-existing workspace PVC when switching images to persist your work.
How do PodDefaults, affinity, and tolerations affect my notebook pod?PodDefaults inject configuration at runtime (for example, environment variables like MLFLOW_TRACKING_URI, credentials, or volume mounts) without changing images. Affinity selects preferred nodes (e.g., CPU tiers or GPU nodes), and tolerations allow scheduling onto tainted nodes. Combined, they control placement (such as accessing GPUs) while keeping user setup simple. You can also toggle shared memory if your framework benefits from it.
Can I customize the notebook spawner menu (images, defaults, node options)?Yes. Edit the jupyter-web-app-config ConfigMap in the kubeflow namespace. You can define default images and a curated list per IDE, make fields read-only, and expose selectable affinity/toleration “profiles” (e.g., small-cpu vs xl-cpu) mapped to node labels/taints. This standardizes environments, improves reproducibility, and lets admins guide users to the right hardware.
How does data passing work in Kubeflow Pipelines v2, and when should I pass values vs files?Each component runs in its own Kubernetes pod. Small values (strings, numbers) flow via task outputs to downstream inputs automatically. For large data, write to an Output[Artifact]/Output[Dataset] and pass that artifact to downstream tasks as Input[…]; read/write using the .path directory or file. Passing paths/artifacts avoids loading huge payloads into memory and mitigates OOMKilled errors.
What changed from KFP v1 to v2 for inputs/outputs and file paths?KFP v1 commonly used InputPath/OutputPath and name suffix rules. KFP v2 prefers strongly typed artifacts: Input[T]/Output[T] (e.g., Dataset, Model, Metrics, HTML, Markdown, or generic Artifact). Access data via the .path property and optionally attach metadata. To migrate, replace Path types with artifacts, pick the right specialized types, use .path for I/O, and remove manual path-suffix handling.
When should I use containerized Python components (target_image) instead of lightweight components?Use containerized Python components when you need faster start-up, complex or non-pip-friendly dependencies, or you want to prebuild and pin environments. Setting target_image builds and pushes an image ahead of execution, then uses it at runtime. This relaxes the “all code inside the function” constraint and speeds runs. Note: it requires a Docker daemon and registry access in your environment.
How do I build a reproducible data preparation pipeline for YOLOv8 object detection?Break the flow into components: (1) download the dataset (e.g., filtered MIDV-500) and extract it, (2) store it in MinIO, (3) split images/labels into train/val/test, and (4) sanity-check outputs. Ensure the YOLOv8 structure: each split has images/ and labels/ with matching filenames; a config file points to dataset root and split folders, and maps class indices to names (e.g., 0: id_card). Pass data between components using Output/Input[Dataset] artifacts and a fixed random_state for reproducibility.
Why convert CSV to Parquet in the MovieLens pipeline, and how is it used?Parquet is a columnar format that typically yields smaller files and faster I/O for analytics workloads. In the MovieLens pipeline, CSVs are converted to Parquet, then split into train/val/test Parquet files, and uploaded to MinIO. This improves efficiency for downstream processing and supports direct access via libraries like pandas or pyarrow. A QA step then validates expected files and basic data assumptions before training.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Machine Learning Platform Engineering ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Machine Learning Platform Engineering ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Machine Learning Platform Engineering ebook for free