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

Kubernetes 고급 리소스와 운영 완벽 가이드 Kubernetes Advanced Resources & Operations Guide

Pod와 Deployment만으로는 프로덕션 환경을 운영할 수 없습니다. 설정 관리, 시크릿 처리, 외부 트래픽 라우팅, 자동 스케일링 등 고급 리소스를 알아봅니다.

You can't run production with just Pods and Deployments. Let's explore advanced resources like config management, secrets, traffic routing, and auto-scaling.

ConfigMap: 설정 외부화 ConfigMap: Externalizing Configuration

ConfigMap은 컨테이너 이미지에서 설정 정보를 분리합니다. 환경별로 다른 설정을 코드 변경 없이 적용할 수 있습니다.

ConfigMap separates configuration from container images. Apply different settings per environment without code changes.

# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DATABASE_HOST: "db.example.com"
  LOG_LEVEL: "info"
  MAX_CONNECTIONS: "100"
# Pod에서 ConfigMap 사용
spec:
  containers:
  - name: app
    envFrom:
    - configMapRef:
        name: app-config
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DATABASE_HOST: "db.example.com"
  LOG_LEVEL: "info"
  MAX_CONNECTIONS: "100"

Secret: 민감 정보 관리 Secret: Managing Sensitive Data

Secret은 비밀번호, API 키, 토큰 등 민감한 정보를 저장합니다. Base64로 인코딩되어 저장됩니다 (암호화 아님!).

Secret stores sensitive info like passwords, API keys, tokens. Stored as Base64 encoded (not encrypted!).

# Secret 생성 (명령형)
$ kubectl create secret generic db-secret \
  --from-literal=password=mysecretpassword

# Secret 목록 확인
$ kubectl get secrets

# Secret 상세 (값은 Base64로 표시됨)
$ kubectl describe secret db-secret
# Create Secret (imperative)
$ kubectl create secret generic db-secret \
  --from-literal=password=mysecretpassword

# List Secrets
$ kubectl get secrets

# Secret details (values shown as Base64)
$ kubectl describe secret db-secret

⚠️ Secret은 기본적으로 암호화되지 않습니다 ⚠️ Secrets are not encrypted by default

etcd에 Base64로만 저장됩니다. 프로덕션에서는 Encryption at Rest를 활성화하거나 HashiCorp Vault 같은 외부 시크릿 관리 도구를 사용하세요.

Only stored as Base64 in etcd. In production, enable Encryption at Rest or use external secret management tools like HashiCorp Vault.

Ingress: 외부 트래픽 라우팅 Ingress: External Traffic Routing

Ingress는 클러스터 외부에서 내부 서비스로 HTTP/HTTPS 라우팅을 제공합니다. 호스트명, 경로 기반 라우팅, TLS 종료를 지원합니다.

Ingress provides HTTP/HTTPS routing from outside the cluster to internal services. Supports hostname, path-based routing, and TLS termination.

# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - host: "api.example.com"
    http:
      paths:
      - path: /v1
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 80
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - host: "api.example.com"
    http:
      paths:
      - path: /v1
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 80

HPA: 자동 스케일링 HPA: Auto Scaling

HorizontalPodAutoscaler는 CPU/메모리 사용량에 따라 Pod 수를 자동으로 조정합니다.

HorizontalPodAutoscaler automatically adjusts Pod count based on CPU/memory usage.

# HPA 생성 (명령형)
$ kubectl autoscale deployment nginx \
  --cpu-percent=70 --min=2 --max=10

# HPA 상태 확인
$ kubectl get hpa

# HPA 상세 정보
$ kubectl describe hpa nginx
# Create HPA (imperative)
$ kubectl autoscale deployment nginx \
  --cpu-percent=70 --min=2 --max=10

# Check HPA status
$ kubectl get hpa

# HPA details
$ kubectl describe hpa nginx

PersistentVolume: 영구 스토리지 PersistentVolume: Persistent Storage

# PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard
# PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard

트러블슈팅 명령어 Troubleshooting Commands

# Pod가 Pending 상태일 때
$ kubectl describe pod pod-name
# → Events 섹션에서 원인 확인

# Pod 이벤트만 확인
$ kubectl get events --sort-by='.lastTimestamp'

# 노드 상태 확인
$ kubectl get nodes
$ kubectl describe node node-name

# 리소스 사용량 확인
$ kubectl top pods
$ kubectl top nodes
# When Pod is in Pending state
$ kubectl describe pod pod-name
# → Check Events section for cause

# View Pod events only
$ kubectl get events --sort-by='.lastTimestamp'

# Check node status
$ kubectl get nodes
$ kubectl describe node node-name

# Check resource usage
$ kubectl top pods
$ kubectl top nodes

💡 k9s: 터미널 기반 K8s 대시보드 💡 k9s: Terminal-based K8s Dashboard

k9s는 터미널에서 Kubernetes 클러스터를 탐색하고 관리할 수 있는 도구입니다. brew install k9s 또는 choco install k9s로 설치하세요.

k9s is a tool to explore and manage Kubernetes clusters from the terminal. Install with brew install k9s or choco install k9s.