이종관
Back to Posts

Kubernetes 심화: 네트워킹, 스토리지, 배포 전략

Service, Ingress, PV/PVC, 롤링 업데이트, RBAC

2025년 2월 5일·5 min read·
infra
kubernetes
networking
storage
deployment
rbac
security

1. 네트워킹 및 서비스

Service 종류

타입접근 범위사용 사례
ClusterIP클러스터 내부마이크로서비스 간 통신
NodePort노드IP:포트개발/테스트 환경
LoadBalancer외부 LB프로덕션 외부 노출

Ingress

HTTP/HTTPS 트래픽에 대한 라우팅 규칙을 정의합니다.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /v1
        pathType: Prefix
        backend:
          service:
            name: api-v1
            port:
              number: 80
      - path: /v2
        pathType: Prefix
        backend:
          service:
            name: api-v2
            port:
              number: 80

Ingress Controller: Nginx, HAProxy, Traefik, Istio Gateway 등

Namespace

클러스터를 논리적으로 분리하여 리소스를 격리/관리합니다.

kubectl create namespace dev
kubectl create namespace prod

NetworkPolicy

Pod 간 트래픽 흐름을 세밀하게 제어합니다.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend
spec:
  podSelector:
    matchLabels:
      app: backend
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: frontend

2. 스토리지

Volume vs PV vs PVC

개념설명
VolumePod 내부 마운트 디렉터리 (emptyDir, hostPath 등)
PersistentVolume (PV)클러스터 레벨 스토리지 리소스
PersistentVolumeClaim (PVC)Pod의 스토리지 요청

PV/PVC 예시

# PersistentVolume
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/my-pv

---
# PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

ConfigMap & Secret

# ConfigMap - 일반 설정
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DATABASE_URL: "postgres://db:5432"
  LOG_LEVEL: "info"

---
# Secret - 민감 정보
apiVersion: v1
kind: Secret
metadata:
  name: app-secret
type: Opaque
data:
  DB_PASSWORD: cGFzc3dvcmQxMjM=  # base64 인코딩

3. 배포 전략

롤링 업데이트 (기본)

spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1        # 추가 Pod 허용 수
      maxUnavailable: 0  # 동시 중단 허용 수
# 배포
kubectl apply -f deployment.yaml

# 롤백
kubectl rollout undo deployment my-deployment

# 히스토리 확인
kubectl rollout history deployment my-deployment

Canary 배포

일부 트래픽(5~10%)만 새 버전에 노출하여 안정성 확인 후 점진 확대

# v1: 9개 replicas
# v2: 1개 replicas (10% 트래픽)

Blue/Green 배포

두 환경(Blue/Green)을 동시 운영하고, 트래픽을 한 번에 전환

# Blue 환경 운영 중
# Green 환경에 새 버전 배포 & 테스트
# Service selector를 Green으로 변경

StatefulSet

상태를 가지는 애플리케이션(DB, 캐시 등) 배포용

  • Pod에 고유한 ID 부여
  • 순서 보장 (생성/삭제)
  • 고유한 PVC 연결
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 3
  selector:
    matchLabels:
      app: postgres
  template:
    # ...
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi

4. 보안 및 접근 제어

RBAC (Role Based Access Control)

# Role - 네임스페이스 내 권한
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: dev
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]

---
# RoleBinding - 사용자에 Role 연결
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: dev
subjects:
- kind: User
  name: developer
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

ClusterRole vs Role

종류범위
Role특정 네임스페이스 내
ClusterRole클러스터 전체

Security Context

Pod/컨테이너 수준 보안 설정

spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
  containers:
  - name: app
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true

정리

주제핵심
네트워킹Service, Ingress, NetworkPolicy
스토리지PV/PVC, ConfigMap, Secret
배포Rolling, Canary, Blue/Green, StatefulSet
보안RBAC, Security Context

쿠버네티스 운영의 핵심은 선언적 구성자동화입니다. YAML로 원하는 상태를 정의하면 쿠버네티스가 그 상태를 유지합니다.