← 가이드 목록으로 ← Back to guides

Kubernetes Helm & 모니터링 완벽 가이드 Kubernetes Helm & Monitoring Complete Guide

프로덕션 Kubernetes 환경에서는 복잡한 애플리케이션을 쉽게 배포하고, 클러스터의 상태를 실시간으로 모니터링해야 합니다. Helm은 패키지 관리자로, PrometheusGrafana는 모니터링 스택으로 이를 해결합니다.

In production Kubernetes environments, you need to easily deploy complex applications and monitor cluster health in real-time. Helm as a package manager, and Prometheus with Grafana as a monitoring stack solve these challenges.

Helm: Kubernetes 패키지 관리자 Helm: Kubernetes Package Manager

Helm은 Kubernetes 애플리케이션을 정의하고 설치하며 업그레이드하는 도구입니다. 복잡한 YAML 파일들을 Chart로 패키징하여 재사용할 수 있습니다.

Helm is a tool that defines, installs, and upgrades Kubernetes applications. It packages complex YAML files into Charts for reusability.

Helm 설치 및 기본 명령어 Helm Installation & Basic Commands

# Helm 설치 (macOS)
$ brew install helm

# Helm 설치 (Windows)
$ choco install kubernetes-helm

# 버전 확인
$ helm version

# 리포지토리 추가
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo update
# Install Helm (macOS)
$ brew install helm

# Install Helm (Windows)
$ choco install kubernetes-helm

# Check version
$ helm version

# Add repository
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo update

Chart 설치 및 관리 Chart Installation & Management

# Chart 검색
$ helm search repo nginx

# Chart 설치
$ helm install my-nginx bitnami/nginx

# 네임스페이스에 설치
$ helm install my-nginx bitnami/nginx -n production

# 설치된 릴리스 목록
$ helm list
$ helm list -A # 모든 네임스페이스

# 릴리스 상태 확인
$ helm status my-nginx

# 릴리스 삭제
$ helm uninstall my-nginx
# Search for Charts
$ helm search repo nginx

# Install a Chart
$ helm install my-nginx bitnami/nginx

# Install to namespace
$ helm install my-nginx bitnami/nginx -n production

# List installed releases
$ helm list
$ helm list -A # all namespaces

# Check release status
$ helm status my-nginx

# Delete release
$ helm uninstall my-nginx

values.yaml로 커스터마이징 Customizing with values.yaml

# 기본 values 확인
$ helm show values bitnami/nginx > values.yaml

# 커스텀 values로 설치
$ helm install my-nginx bitnami/nginx -f values.yaml

# 인라인으로 값 지정
$ helm install my-nginx bitnami/nginx \
  --set replicaCount=3 \
  --set service.type=LoadBalancer
# View default values
$ helm show values bitnami/nginx > values.yaml

# Install with custom values
$ helm install my-nginx bitnami/nginx -f values.yaml

# Set values inline
$ helm install my-nginx bitnami/nginx \
  --set replicaCount=3 \
  --set service.type=LoadBalancer

💡 Helm 업그레이드 & 롤백 💡 Helm Upgrade & Rollback

# 릴리스 업그레이드
$ helm upgrade my-nginx bitnami/nginx -f new-values.yaml

# 히스토리 확인
$ helm history my-nginx

# 이전 버전으로 롤백
$ helm rollback my-nginx 1

Prometheus: 메트릭 수집 Prometheus: Metrics Collection

Prometheus는 시계열 데이터베이스로, Kubernetes 클러스터의 메트릭을 수집하고 저장합니다. Pull 기반으로 타겟에서 메트릭을 가져오며, PromQL로 쿼리합니다.

Prometheus is a time-series database that collects and stores metrics from Kubernetes clusters. It pulls metrics from targets and queries them with PromQL.

kube-prometheus-stack 설치 Installing kube-prometheus-stack

# prometheus-community 리포지토리 추가
$ helm repo add prometheus-community \
  https://prometheus-community.github.io/helm-charts
$ helm repo update

# 모니터링 네임스페이스 생성
$ kubectl create namespace monitoring

# kube-prometheus-stack 설치
$ helm install prometheus \
  prometheus-community/kube-prometheus-stack \
  -n monitoring
# Add prometheus-community repository
$ helm repo add prometheus-community \
  https://prometheus-community.github.io/helm-charts
$ helm repo update

# Create monitoring namespace
$ kubectl create namespace monitoring

# Install kube-prometheus-stack
$ helm install prometheus \
  prometheus-community/kube-prometheus-stack \
  -n monitoring

PromQL 기본 쿼리 Basic PromQL Queries

# CPU 사용량
sum(rate(container_cpu_usage_seconds_total{namespace="default"}[5m])) by (pod)

# 메모리 사용량 (MB)
sum(container_memory_usage_bytes{namespace="default"}) by (pod) / 1024 / 1024

# HTTP 요청 수
sum(rate(http_requests_total[5m])) by (service)

# 에러율
sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))
# CPU usage
sum(rate(container_cpu_usage_seconds_total{namespace="default"}[5m])) by (pod)

# Memory usage (MB)
sum(container_memory_usage_bytes{namespace="default"}) by (pod) / 1024 / 1024

# HTTP request count
sum(rate(http_requests_total[5m])) by (service)

# Error rate
sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))

Grafana: 대시보드 시각화 Grafana: Dashboard Visualization

Grafana는 Prometheus의 데이터를 아름다운 대시보드로 시각화합니다. kube-prometheus-stack에 이미 포함되어 있으며, 기본 대시보드도 제공됩니다.

Grafana visualizes Prometheus data in beautiful dashboards. It's already included in kube-prometheus-stack with default dashboards.

# Grafana 포트포워딩
$ kubectl port-forward -n monitoring \
  svc/prometheus-grafana 3000:80

# 기본 접속 정보
# URL: http://localhost:3000
# Username: admin
# Password: prom-operator (기본값)

# Grafana admin 비밀번호 확인
$ kubectl get secret -n monitoring \
  prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d
# Port-forward Grafana
$ kubectl port-forward -n monitoring \
  svc/prometheus-grafana 3000:80

# Default credentials
# URL: http://localhost:3000
# Username: admin
# Password: prom-operator (default)

# Get Grafana admin password
$ kubectl get secret -n monitoring \
  prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d

📊 추천 Grafana 대시보드 📊 Recommended Grafana Dashboards

  • 315: Kubernetes Cluster Overview
  • 6417: Kubernetes Pods
  • 13770: Node Exporter Full
  • 7249: Kubernetes Capacity
  • 315: Kubernetes Cluster Overview
  • 6417: Kubernetes Pods
  • 13770: Node Exporter Full
  • 7249: Kubernetes Capacity

Grafana.com에서 Dashboard ID로 검색하여 임포트할 수 있습니다.

Search by Dashboard ID on Grafana.com to import.

알림 (Alerting) 설정 Alerting Configuration

Alertmanager는 Prometheus의 알림을 라우팅하고 관리합니다. Slack, Email, PagerDuty 등 다양한 채널로 알림을 보낼 수 있습니다.

Alertmanager routes and manages Prometheus alerts. It can send alerts to various channels like Slack, Email, PagerDuty, etc.

# alertmanager-config.yaml
global:
  slack_api_url: 'https://hooks.slack.com/...'

route:
  receiver: 'slack-notifications'
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h

receivers:
  - name: 'slack-notifications'
    slack_configs:
    - channel: '#alerts'
      title: '{{ .Status }}: {{ .CommonLabels.alertname }}'
# alertmanager-config.yaml
global:
  slack_api_url: 'https://hooks.slack.com/...'

route:
  receiver: 'slack-notifications'
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h

receivers:
  - name: 'slack-notifications'
    slack_configs:
    - channel: '#alerts'
      title: '{{ .Status }}: {{ .CommonLabels.alertname }}'

⚠️ 리소스 사용량 주의 ⚠️ Resource Usage Warning

Prometheus와 Grafana는 상당한 리소스를 사용합니다. 소규모 클러스터에서는 retention 기간을 줄이거나 리소스 제한을 설정하세요.

Prometheus and Grafana consume significant resources. For small clusters, reduce retention period or set resource limits.

로그 수집: Loki Log Collection: Loki

Loki는 Grafana에서 만든 로그 집계 시스템입니다. Prometheus와 비슷한 방식으로 작동하며, 라벨 기반 인덱싱을 사용합니다.

Loki is a log aggregation system created by Grafana. It works similarly to Prometheus with label-based indexing.

# Loki 스택 설치
$ helm repo add grafana https://grafana.github.io/helm-charts
$ helm install loki-stack grafana/loki-stack \
  -n monitoring \
  --set promtail.enabled=true \
  --set grafana.enabled=false # 이미 설치됨
# Install Loki stack
$ helm repo add grafana https://grafana.github.io/helm-charts
$ helm install loki-stack grafana/loki-stack \
  -n monitoring \
  --set promtail.enabled=true \
  --set grafana.enabled=false # already installed

💡 모니터링 스택 구성 요약 💡 Monitoring Stack Summary

  • Prometheus: 메트릭 수집 및 저장
  • Alertmanager: 알림 라우팅 및 관리
  • Grafana: 시각화 대시보드
  • Loki: 로그 집계
  • Promtail: 로그 수집 에이전트
  • Prometheus: Metrics collection & storage
  • Alertmanager: Alert routing & management
  • Grafana: Visualization dashboards
  • Loki: Log aggregation
  • Promtail: Log collection agent