🤖 AI/ML

Kubeflow

Kubeflow

Kubernetes 기반 ML 워크플로우 플랫폼. 파이프라인, 서빙 등 제공.

📖 상세 설명

Kubeflow는 Kubernetes 위에서 ML 워크플로우를 구축, 배포, 관리하기 위한 오픈소스 플랫폼입니다. Google이 2017년 시작한 프로젝트로, ML 파이프라인의 End-to-End 자동화를 목표로 합니다. 현재 CNCF(Cloud Native Computing Foundation) 프로젝트입니다.

기존 ML 개발의 문제는 "내 노트북에서는 돌아가는데 프로덕션에서 안 됨" 이었습니다. Kubeflow는 컨테이너 기반으로 환경 일관성을 보장하고, 실험부터 배포까지 동일한 플랫폼에서 관리합니다.

핵심 컴포넌트: Kubeflow Pipelines(워크플로우 DAG), KServe(모델 서빙), Katib(하이퍼파라미터 튜닝), Training Operators(분산학습). 각각 독립 배포 가능하며, 필요한 것만 선택적으로 사용할 수 있습니다.

실무에서 Kubeflow는 대규모 ML 팀의 표준 인프라입니다. 데이터 전처리 → 학습 → 평가 → 배포 파이프라인을 코드로 정의하고, 버전 관리와 재현성을 확보합니다. AWS SageMaker, GCP Vertex AI의 온프레미스 대안으로 많이 사용됩니다.

💻 코드 예제

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에서 업로드

📊 성능 & 비용

2025년 1월 기준 Kubeflow 인프라 비용 예상입니다.

항목 사양/가격 비고
Kubeflow 소프트웨어 오픈소스 (무료) Apache 2.0 라이선스
최소 클러스터 (개발) 3 x n1-standard-4 ~$300/월 (GKE)
프로덕션 클러스터 5+ 노드, 16+ vCPU 각 ~$1,500/월 (GKE/EKS)
GPU 노드 (A100 40GB) $2.95/시간 (GCP) 학습 시간만 요금 발생
GPU 노드 (T4) $0.35/시간 (GCP) 추론/경량 학습용
컴포넌트 최소 리소스 권장 리소스
Kubeflow Pipelines 4 vCPU, 8GB RAM 8 vCPU, 16GB RAM
KServe (모델 서빙) 2 vCPU, 4GB RAM 모델 크기에 따라
Katib (AutoML) 2 vCPU, 4GB RAM 병렬 실험 수에 따라

비용 절감 팁: Spot/Preemptible 인스턴스로 학습 비용 60-70% 절감. 자동 스케일링으로 유휴 리소스 최소화.

🗣️ 실무에서 이렇게 말하세요

💬 회의에서
"현재 학습 스크립트가 Jupyter에 흩어져 있어서 재현이 안 됩니다. Kubeflow Pipelines로 전처리-학습-평가-배포를 DAG로 묶으면, 한 번 클릭으로 전체 파이프라인 실행되고 버전 관리도 가능합니다."
💬 면접에서
"온프레미스 GPU 클러스터에 Kubeflow 1.8을 구축했습니다. Katib으로 하이퍼파라미터 튜닝 자동화하고, KServe로 A/B 테스트 배포까지 한 달 만에 MLOps 파이프라인 완성했습니다. 모델 배포 주기가 2주에서 2일로 단축됐어요."
💬 기술 토론에서
"Kubeflow vs Airflow 비교하면, Airflow는 범용 워크플로우고 Kubeflow는 ML 특화입니다. GPU 스케줄링, 분산학습, 모델 서빙이 내장되어 있어서 ML 팀에는 Kubeflow가 더 적합해요."

⚠️ 흔한 실수 & 주의사항

Full Kubeflow를 무조건 설치

전체 설치 시 30개 이상 컴포넌트가 올라가 리소스 낭비. 필요한 것만 선택 설치하세요 (예: Pipelines + KServe만).

Kubernetes 경험 없이 바로 Kubeflow 도입

k8s 기본 개념(Pod, Service, PVC) 없이 시작하면 디버깅 불가. 최소 CKA 수준 지식 필요합니다.

올바른 방법

minikube나 kind로 로컬 테스트 후, 프로덕션은 EKS/GKE Autopilot 권장. Kubeflow Manifests로 버전 관리하세요.

🔗 관련 용어

📚 더 배우기