Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

130 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

kcloud-cost-estimator

Kubernetes ν΄λŸ¬μŠ€ν„° μ „λ ₯ 데이터 μˆ˜μ§‘ 및 μ—λ„ˆμ§€ 예츑 λͺ¨λ“ˆ

XGBoost 기반 AI μ›Œν¬λ‘œλ“œ 예츑

  • λͺ¨λΈ 기반 예츑: νŒŒλΌλ―Έν„° 수, 배치 크기 반영
  • κ³ μ •λ°€ μ „λ ₯ μΆ”μ •: μ‹€μΈ‘ 데이터 기반 ν•™μŠ΅ λͺ¨λΈ 적용

μ£Όμš” κΈ°λŠ₯

Power λ©”νŠΈλ¦­ μˆ˜μ§‘

  • μ‹€μ‹œκ°„ μ „λ ₯ 데이터: μ»¨ν…Œμ΄λ„ˆ/λ…Έλ“œλ³„ μ „λ ₯ μ†ŒλΉ„λŸ‰
  • GPU/NPU μ „λ ₯ λͺ¨λ‹ˆν„°λ§: AI 가속기 νŠΉν™” λ©”νŠΈλ¦­
  • μ›Œν¬λ‘œλ“œλ³„ μ „λ ₯ ν”„λ‘œνŒŒμΌλ§: μž‘μ—… μœ ν˜•λ³„ μ „λ ₯ νŒ¨ν„΄ 뢄석

데이터 처리 νŒŒμ΄ν”„λΌμΈ

  • λ©”νŠΈλ¦­ μ •κ·œν™”: Power raw data β†’ ν‘œμ€€ν™”λœ μ „λ ₯ λ©”νŠΈλ¦­
  • λΉ„μš© ν™˜μ‚°: μ „λ ₯ μ†ŒλΉ„λŸ‰ β†’ 운용 λΉ„μš© 계산
  • μ‹€μ‹œκ°„ 슀트리밍: Redis/DBλ₯Ό ν†΅ν•œ 데이터 전솑

μ—λ„ˆμ§€ 예츑 (Energy Prediction)

  • ARIMA 기반 μ›Œν¬λ‘œλ“œ 예츑: κ³Όκ±° νŒ¨ν„΄ 기반 미래 CPU μ‚¬μš©λŸ‰ 예츑
  • 4단계 예츑 ν”„λ ˆμž„μ›Œν¬: μ»¨ν…Œμ΄λ„ˆ β†’ λ…Έλ“œ β†’ μ „λ ₯ β†’ λΆ„λ°°
  • μžλ™ λͺ¨λΈ 보정: μ‹€μΈ‘ 데이터 기반 μ„ ν˜• νšŒκ·€ νŒŒλΌλ―Έν„° μžλ™ μ‘°μ •
  • 배포 μ „ μ—λ„ˆμ§€ 예츑: μ»¨ν…Œμ΄λ„ˆ 배포 μ „ μ „λ ₯ μ†ŒλΉ„λŸ‰ 사전 νŒŒμ•…

μ°Έκ³  λ…Όλ¬Έ: Alzamil, I., & Djemame, K. (2017). Energy Prediction for Cloud Workload Patterns. GECON 2016: Economics of Grids, Clouds, Systems, and Services, pp. 160-174.

μ•„ν‚€ν…μ²˜

Power Exporter (Prometheus)
    ↓ HTTP/Prometheus API
PowerClient β†’ PowerMetrics β†’ DataProcessor
    ↓                ↓             ↓
  μˆ˜μ§‘          μ •κ·œν™”/집계      λΉ„μš©ν™˜μ‚°
    ↓                ↓             ↓
Redis Queue ← InfluxDB ← analyzer/predictor λͺ¨λ“ˆ

핡심 λ©”νŠΈλ¦­

Power λ©”νŠΈλ¦­ λ§€ν•‘

power_metrics:
  container_power:
    - kepler_container_joules_total          # μ»¨ν…Œμ΄λ„ˆ 총 μ „λ ₯
    - kepler_container_core_joules_total     # CPU μ „λ ₯
    - kepler_container_dram_joules_total     # DRAM μ „λ ₯
    - kepler_container_gpu_joules_total      # GPU μ „λ ₯
    - kepler_container_other_joules_total    # 기타 ν•˜λ“œμ›¨μ–΄

  node_power:
    - kepler_node_platform_joules_total      # λ…Έλ“œ ν”Œλž«νΌ μ „λ ₯
    - kepler_node_core_joules_total          # λ…Έλ“œ CPU μ „λ ₯
    - kepler_node_dram_joules_total          # λ…Έλ“œ DRAM μ „λ ₯

  workload_classification:
    - pod_name, namespace, workload_type
    - container_name, image, command

λΉ„μš© ν™˜μ‚° 곡식

# src/power_metrics/cost_calculator.py
def calculate_power_cost(power_watts, duration_hours):
    electricity_cost = power_watts * (duration_hours / 1000) * ELECTRICITY_RATE
    cooling_overhead = electricity_cost * COOLING_FACTOR
    carbon_cost = (power_watts * duration_hours / 1000) * CARBON_RATE
    return electricity_cost + cooling_overhead + carbon_cost

μ„€μ •

ν™˜κ²½λ³€μˆ˜

# Prometheus μ—°κ²°
POWER_PROMETHEUS_URL=http://prometheus:9090
POWER_METRICS_INTERVAL=15

# λΉ„μš© 계산
ELECTRICITY_RATE=0.12  # $/kWh
COOLING_FACTOR=1.3     # 냉각 μ˜€λ²„ν—€λ“œ
CARBON_RATE=0.05       # $/kg CO2

# 데이터 μ €μž₯
REDIS_URL=redis://localhost:6379
INFLUXDB_URL=http://influxdb:8086
INFLUXDB_BUCKET=power_metrics

API μ—”λ“œν¬μΈνŠΈ

μ „λ ₯ 데이터 μˆ˜μ§‘

# μ‹€μ‹œκ°„ μ „λ ₯ 데이터
GET /power/current?workload=ml-training&namespace=default
GET /power/containers?namespace=kcloud-workloads
GET /power/nodes

# λΉ„μš© 뢄석 데이터
GET /cost/current?namespace=default
GET /cost/hourly?start=2025-01-01T00:00:00Z
GET /cost/workload/{workload_id}

# μ „λ ₯ ν”„λ‘œνŒŒμΌ
GET /profile/workload-types
POST /profile/classify

μ—λ„ˆμ§€ 예츑

# μ»¨ν…Œμ΄λ„ˆ μ—λ„ˆμ§€ 예츑
POST /predict/energy
# Request Body:
{
  "container_name": "ml-trainer",
  "pod_name": "ml-trainer-abc123",
  "namespace": "default",
  "historical_cpu_cores": [0.8, 0.85, 0.9, ...],
  "container_cpu_request": 1.0,
  "node_current_util": 45.0,
  "node_idle_util": 5.0,
  "containers_on_node": [],
  "prediction_horizon_minutes": 30
}
# Response:
{
  "prediction": {
    "predicted_power_watts": 12.5,
    "confidence_interval": [11.2, 13.8],
    "prediction_timestamp": "2025-01-26T10:00:00Z"
  }
}

# λͺ¨λΈ 보정
POST /calibrate
# Request Body:
{
  "container_node_data": [
    {"container_cpu_cores": 0.5, "node_cpu_util_percent": 15.2},
    {"container_cpu_cores": 1.0, "node_cpu_util_percent": 28.5}
  ],
  "node_power_data": [
    {"node_cpu_util_percent": 0, "node_power_watts": 54.0},
    {"node_cpu_util_percent": 50, "node_power_watts": 85.2}
  ]
}
# Response:
{
  "calibration": {
    "container_to_node_slope": 23.993,
    "container_to_node_intercept": 4.124,
    "node_util_to_power_slope": 0.7254,
    "node_util_to_power_intercept": 53.97
  }
}

# 보정 μ„€μ • 쑰회
GET /calibration/config
# Response: ν˜„μž¬ μ‚¬μš© 쀑인 calibration νŒŒλΌλ―Έν„°

μ‚¬μš© μ˜ˆμ‹œ

Python ν΄λΌμ΄μ–ΈνŠΈ

from src.power_client import PowerClient
from src.power_metrics import PowerCalculator

# μ „λ ₯ 데이터 μˆ˜μ§‘
client = PowerClient(prometheus_url="http://prometheus:9090")
power_data = client.get_container_power_metrics(
    namespace="kcloud-workloads",
    time_range="5m"
)

# λΉ„μš© 계산
calculator = PowerCalculator()
cost = calculator.calculate_total_cost(power_data)
print(f"μ›Œν¬λ‘œλ“œ 운용 λΉ„μš©: ${cost:.2f}/hour")

μ—λ„ˆμ§€ 예츑 μ‚¬μš©

from src.predictor import EnergyPredictor, HistoricalData
from datetime import datetime, timedelta

# κ³Όκ±° CPU μ‚¬μš©λŸ‰ 데이터 μ€€λΉ„
historical_data = HistoricalData(
    timestamps=[datetime.utcnow() - timedelta(minutes=i) for i in range(90, 0, -1)],
    values=[0.8] * 90,  # 90λΆ„κ°„ 0.8 cores μ‚¬μš©
    metric_name="cpu_cores"
)

# 예츑 μ‹€ν–‰
predictor = EnergyPredictor()
prediction = predictor.predict_container_energy(
    container_name="nginx-server",
    pod_name="nginx-deploy-abc123",
    namespace="production",
    historical_workload=historical_data,
    container_cpu_request=1.0,
    node_current_util=45.0,
    node_idle_util=5.0,
    containers_on_node=[],
    prediction_horizon_minutes=30
)

print(f"μ˜ˆμƒ μ „λ ₯ μ†ŒλΉ„: {prediction.predicted_power_watts:.2f} watts")

배포

둜컬 개발

# κ°€μƒν™˜κ²½ 생성 및 μ˜μ‘΄μ„± μ„€μΉ˜
make install

# 개발 λͺ¨λ“œ μ‹€ν–‰
make run

# ν…ŒμŠ€νŠΈ μ‹€ν–‰
make test

Dockerμ—μ„œ μ „λ ₯ 예츑 API μ‹€ν–‰

make run은 둜컬 μˆ˜μ§‘ APIλ₯Ό 8001번 ν¬νŠΈμ—μ„œ μ‹€ν–‰ν•©λ‹ˆλ‹€. 이 μ €μž₯μ†Œμ˜ Dockerfile은 μ „λ ₯ 예츑 APIλ₯Ό μ»¨ν…Œμ΄λ„ˆμ˜ 8000번 ν¬νŠΈμ—μ„œ μ‹€ν–‰ν•©λ‹ˆλ‹€.

make docker-build
docker run --detach --rm --name kcloud-power-predictor \
  --publish 127.0.0.1:8001:8000 kcloud-cost-estimator:latest

μ„œλ²„κ°€ μ‹œμž‘λ˜λ©΄ μ•„λž˜ μš”μ²­μœΌλ‘œ μƒνƒœμ™€ λͺ¨λΈ λ‘œλ”© μ—¬λΆ€λ₯Ό ν™•μΈν•©λ‹ˆλ‹€.

curl --fail --silent --show-error http://127.0.0.1:8001/health

serviceκ°€ ml-power-predictor이고 model_trainedκ°€ true이면 /docsμ—μ„œ POST /api/v1/predict/powerλ₯Ό μ‹€ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λͺ¨λΈμ΄ μ€€λΉ„λ˜μ§€ μ•ŠμœΌλ©΄ 예츑 μš”μ²­μ€ HTTP 503을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

docker logs kcloud-power-predictor
docker stop kcloud-power-predictor

Kubernetes 배포

# 1. Docker 이미지 λΉŒλ“œ
make docker-build

# 2. K8s λ¦¬μ†ŒμŠ€ 배포 (λ„€μž„μŠ€νŽ˜μ΄μŠ€, RBAC, ConfigMap, Deployment, Service, HPA)
make k8s-deploy

# 3. 배포 μƒνƒœ 확인
make k8s-status

# 4. 포트 ν¬μ›Œλ”©μœΌλ‘œ 둜컬 μ ‘κ·Ό
make k8s-port-forward

# 5. Health Check
curl -f http://localhost:8001/health

# 6. 둜그 확인
make k8s-logs

# 7. 재배포 (μ½”λ“œ λ³€κ²½ ν›„)
make k8s-build-deploy

# 8. 전체 μ‚­μ œ
make k8s-delete

배포된 λ¦¬μ†ŒμŠ€

  • Namespace: kcloud-system
  • ServiceAccount: RBAC κΆŒν•œ λΆ€μ—¬ (λ…Έλ“œ/νŒŒλ“œ λ©”νŠΈλ¦­ 쑰회)
  • ConfigMap: ν™˜κ²½ λ³€μˆ˜ μ„€μ • (Prometheus URL, λΉ„μš© 계산 νŒŒλΌλ―Έν„° λ“±)
  • Deployment: 2개 λ ˆν”Œλ¦¬μΉ΄λ‘œ μ‹œμž‘ (λ¦¬μ†ŒμŠ€ μ œν•œ: 100m-500m CPU, 256Mi-512Mi λ©”λͺ¨λ¦¬)
  • Service: ClusterIP둜 λ‚΄λΆ€ 톡신 (8001 포트)
  • HPA: CPU/λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰ 기반 μ˜€ν† μŠ€μΌ€μΌλ§ (2-5 λ ˆν”Œλ¦¬μΉ΄)

ν”„λ‘œμ νŠΈ ꡬ쑰

kcloud-cost-estimator/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.py                    # FastAPI μ• ν”Œλ¦¬μΌ€μ΄μ…˜
β”‚   β”œβ”€β”€ power_client/              # μ „λ ₯ 데이터 μˆ˜μ§‘
β”‚   β”‚   └── client.py
β”‚   β”œβ”€β”€ power_metrics/             # λ©”νŠΈλ¦­ 처리
β”‚   β”œβ”€β”€ data_processor/            # 데이터 ν”„λ‘œμ„Έμ‹±
β”‚   β”œβ”€β”€ predictor/                 # μ—λ„ˆμ§€ 예츑 λͺ¨λ“ˆ
β”‚   β”‚   β”œβ”€β”€ models.py              # 데이터 λͺ¨λΈ
β”‚   β”‚   β”œβ”€β”€ workload_predictor.py  # ARIMA μ›Œν¬λ‘œλ“œ 예츑
β”‚   β”‚   β”œβ”€β”€ energy_predictor.py    # 4단계 μ—λ„ˆμ§€ 예츑
β”‚   β”‚   β”œβ”€β”€ calibration.py         # λͺ¨λΈ 보정 도ꡬ
β”‚   β”‚   └── prometheus_helper.py   # Prometheus 쿼리 헬퍼
β”‚   └── config/
β”‚       └── settings.py
β”œβ”€β”€ config/                        # μ„€μ • 파일
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── settings.py                # ν™˜κ²½ λ³€μˆ˜ μ„€μ •
β”œβ”€β”€ demo/                          # 예제 및 데λͺ¨ μ½”λ“œ
β”‚   β”œβ”€β”€ example_prediction.py      # 예츑 μ‚¬μš© 예제
β”‚   └── predictor/                 # 예츑 λͺ¨λ“ˆ ν…ŒμŠ€νŠΈ
β”œβ”€β”€ deployment/                    # K8s 배포 λ§€λ‹ˆνŽ˜μŠ€νŠΈ
β”‚   β”œβ”€β”€ namespace.yaml             # kcloud-system λ„€μž„μŠ€νŽ˜μ΄μŠ€
β”‚   β”œβ”€β”€ rbac.yaml                  # ServiceAccount, ClusterRole, ClusterRoleBinding
β”‚   β”œβ”€β”€ configmap.yaml             # ν™˜κ²½ λ³€μˆ˜ μ„€μ •
β”‚   β”œβ”€β”€ deployment.yaml            # Pod 배포 μ„€μ •
β”‚   β”œβ”€β”€ service.yaml               # ClusterIP μ„œλΉ„μŠ€
β”‚   └── hpa.yaml                   # Horizontal Pod Autoscaler
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Makefile
└── README.md

λΌμ΄μ„ΌμŠ€

Apache License 2.0

API Specification

Workload-aware Prediction

  • POST /predict/workload-aware: Predict power for AI/ML jobs.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages