🤖 AI/ML

Kubeflow

Kubeflow

A Kubernetes-based ML workflow platform. Provides pipelines, serving, and more.

📖 Detailed Explanation

Kubeflow is an open-source platform for building, deploying, and managing ML workflows on Kubernetes. Started by Google in 2017, the project aims to automate ML pipelines end to end. It is currently a CNCF (Cloud Native Computing Foundation) project.

The problem with traditional ML development was "it works on my laptop but not in production." Kubeflow guarantees environment consistency through containers and manages everything from experimentation to deployment on the same platform.

Core components: Kubeflow Pipelines (workflow DAGs), KServe (model serving), Katib (hyperparameter tuning), Training Operators (distributed training). Each can be deployed independently, so you can selectively use only what you need.

In practice, Kubeflow is the standard infrastructure for large ML teams. You define the pipeline of data preprocessing → training → evaluation → deployment as code, and secure version control and reproducibility. It is widely used as an on-premises alternative to AWS SageMaker and GCP Vertex AI.

💻 Code Example

from kfp import dsl, compiler
from kfp.dsl import component, OutputPath, InputPath

# 1. 컴포넌트 정의 (각 단계를 컨테이너로)
@component(base_image="python:3.9")
def preprocess_data(input_path: str, output_path: OutputPath()):
    """데이터 전처리 컴포넌트"""
    import pandas as pd
    df = pd.read_csv(input_path)
    df_clean = df.dropna()
    df_clean.to_csv(output_path, index=False)
    print(f"Preprocessed: {len(df)} -> {len(df_clean)} rows")

@component(base_image="pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime")
def train_model(data_path: InputPath(), model_path: OutputPath(), epochs: int = 10):
    """모델 학습 컴포넌트"""
    import torch
    # 학습 로직...
    torch.save(model.state_dict(), model_path)

@component(base_image="python:3.9")
def deploy_model(model_path: InputPath(), endpoint_name: str):
    """KServe로 모델 배포"""
    # KServe InferenceService 생성 로직
    print(f"Deployed to {endpoint_name}")

# 2. 파이프라인 정의
@dsl.pipeline(name="ML Training Pipeline", description="End-to-end ML pipeline")
def ml_pipeline(data_url: str, epochs: int = 20):
    # DAG 형태로 파이프라인 구성
    preprocess_task = preprocess_data(input_path=data_url)
    train_task = train_model(
        data_path=preprocess_task.outputs['output_path'],
        epochs=epochs
    ).set_gpu_limit(1)  # GPU 할당
    deploy_task = deploy_model(
        model_path=train_task.outputs['model_path'],
        endpoint_name="prod-model"
    )

# 3. 컴파일 & 실행
compiler.Compiler().compile(ml_pipeline, 'pipeline.yaml')
# kubectl apply -f pipeline.yaml 또는 Kubeflow UI에서 업로드

📊 Performance & Cost

This is an estimate of Kubeflow infrastructure costs as of January 2025.

Item Specs/Pricing Notes
Kubeflow software Open source (free) Apache 2.0 license
Minimum cluster (development) 3 x n1-standard-4 ~$300/month (GKE)
Production cluster 5+ nodes, 16+ vCPUs each ~$1,500/month (GKE/EKS)
GPU node (A100 40GB) $2.95/hour (GCP) Charged only for training time
GPU node (T4) $0.35/hour (GCP) For inference/lightweight training
Component Minimum resources Recommended resources
Kubeflow Pipelines 4 vCPU, 8GB RAM 8 vCPU, 16GB RAM
KServe (model serving) 2 vCPU, 4GB RAM Depends on model size
Katib (AutoML) 2 vCPU, 4GB RAM Depends on the number of parallel experiments

Cost-saving tips: Reduce training costs by 60-70% with Spot/Preemptible instances. Minimize idle resources with autoscaling.

🗣️ Say It Like This in Practice

💬 In a Meeting
"Our current training scripts are scattered across Jupyter notebooks, so we can't reproduce results. If we bundle preprocessing, training, evaluation, and deployment into a DAG with Kubeflow Pipelines, we can run the entire pipeline with one click and also version it."
💬 In an Interview
"We built Kubeflow 1.8 on an on-premises GPU cluster. We automated hyperparameter tuning with Katib and completed the MLOps pipeline, including A/B test deployment with KServe, in one month. The model deployment cycle was shortened from 2 weeks to 2 days."
💬 In a Technical Discussion
"Comparing Kubeflow vs Airflow, Airflow is a general-purpose workflow tool, while Kubeflow is specialized for ML. GPU scheduling, distributed training, and model serving are built in, so Kubeflow is a better fit for ML teams."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Installing full Kubeflow unconditionally

A full installation brings up more than 30 components, wasting resources. Install only what you need (e.g., just Pipelines + KServe).

❌
Adopting Kubeflow without Kubernetes experience

If you start without basic k8s concepts (Pod, Service, PVC), you can't debug. Knowledge at least at the CKA level is required.

✅
The right way

After testing locally with minikube or kind, we recommend EKS/GKE Autopilot for production. Manage versions with Kubeflow Manifests.

🔗 Related Terms

📚 Learn More