Kubernetes ν΄λ¬μ€ν° μ λ ₯ λ°μ΄ν° μμ§ λ° μλμ§ μμΈ‘ λͺ¨λ
- λͺ¨λΈ κΈ°λ° μμΈ‘: νλΌλ―Έν° μ, λ°°μΉ ν¬κΈ° λ°μ
- κ³ μ λ° μ λ ₯ μΆμ : μ€μΈ‘ λ°μ΄ν° κΈ°λ° νμ΅ λͺ¨λΈ μ μ©
- μ€μκ° μ λ ₯ λ°μ΄ν°: 컨ν μ΄λ/λ Έλλ³ μ λ ₯ μλΉλ
- GPU/NPU μ λ ₯ λͺ¨λν°λ§: AI κ°μκΈ° νΉν λ©νΈλ¦
- μν¬λ‘λλ³ μ λ ₯ νλ‘νμΌλ§: μμ μ νλ³ μ λ ₯ ν¨ν΄ λΆμ
- λ©νΈλ¦ μ κ·ν: Power raw data β νμ€νλ μ λ ₯ λ©νΈλ¦
- λΉμ© νμ°: μ λ ₯ μλΉλ β μ΄μ© λΉμ© κ³μ°
- μ€μκ° μ€νΈλ¦¬λ°: Redis/DBλ₯Ό ν΅ν λ°μ΄ν° μ μ‘
- 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_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# μ€μκ° μ λ ₯ λ°μ΄ν°
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 νλΌλ―Έν°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 testmake 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/healthserviceκ° ml-power-predictorμ΄κ³ model_trainedκ° trueμ΄λ©΄
/docsμμ POST /api/v1/predict/powerλ₯Ό
μ€νν μ μμ΅λλ€. λͺ¨λΈμ΄ μ€λΉλμ§ μμΌλ©΄ μμΈ‘ μμ²μ HTTP 503μ λ°νν©λλ€.
docker logs kcloud-power-predictor
docker stop kcloud-power-predictor# 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
- POST
/predict/workload-aware: Predict power for AI/ML jobs.