k8s 1주 3일차 - 배포 전략 ( POD vs DEPLOYMENT)

진웅·2025년 5월 26일

K8S Basics

목록 보기
4/41

Pod와 Deployment YAML 파일의 차이점을 비교해서 설명드리겠습니다.

📋 기본 구조 차이

Pod YAML

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.21
    ports:
    - containerPort: 80

Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80

🔍 주요 차이점 분석

1. API 버전과 Kind

# Pod
apiVersion: v1
kind: Pod

# Deployment  
apiVersion: apps/v1
kind: Deployment

2. 구조 복잡도

  • Pod: 단순한 1단계 구조
  • Deployment: 2단계 중첩 구조 (Deployment → Pod Template)

3. 핵심 추가 필드들

Deployment만 가지는 필드들:

spec:
  replicas: 3                    # Pod 복제 개수
  selector:                      # 관리할 Pod 선택 기준
    matchLabels:
      app: nginx
  template:                      # Pod 템플릿 (Pod spec이 여기 들어감)
    metadata:
      labels:
        app: nginx
    spec:
      # 여기가 Pod의 spec과 동일

📊 구조적 관계

Deployment
├── metadata (Deployment 정보)
├── spec
    ├── replicas (복제본 수)
    ├── selector (어떤 Pod를 관리할지)
    └── template
        ├── metadata (Pod의 metadata)
        └── spec (Pod의 spec - 컨테이너 정의 등)

💡 실제 비교 예시

Pod 직접 생성

# simple-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-nginx
spec:
  containers:
  - name: nginx
    image: nginx

같은 Pod를 Deployment로 생성

# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx-deployment
spec:
  replicas: 1                    # 1개만 생성
  selector:
    matchLabels:
      app: nginx
  template:                      # 위의 Pod spec이 여기 들어감
    metadata:
      labels:
        app: nginx               # selector와 매칭되어야 함
    spec:
      containers:
      - name: nginx
        image: nginx

🎯 핵심 포인트

1. Template 개념

  • Deployment의 template 부분이 바로 Pod의 정의입니다
  • template.spec는 Pod의 spec와 완전히 동일

2. Label 매칭

  • selector.matchLabelstemplate.metadata.labels가 일치해야 함
  • 이를 통해 Deployment가 어떤 Pod를 관리할지 결정

3. 중복 제거

  • Pod에서는 metadata.name으로 직접 이름 지정
  • Deployment에서는 자동으로 이름 생성 (deployment-name-xxx-xxx)

🧪 실습으로 확인해보기

# 1. Pod 직접 생성
kubectl apply -f simple-pod.yaml
kubectl get pods
# 결과: my-nginx

# 2. Deployment 생성  
kubectl apply -f nginx-deployment.yaml
kubectl get pods
# 결과: my-nginx-deployment-xxxxxxxxx-xxxxx

# 3. 구조 비교
kubectl describe pod my-nginx
kubectl describe deployment my-nginx-deployment

📋 요약

항목PodDeployment
구조단순 1단계2단계 중첩
핵심 목적컨테이너 실행Pod 관리
고유 필드-replicas, selector, template
관리 방식수동자동 (복제, 복구, 업데이트)

결론: Deployment YAML은 Pod YAML을 template 안에 감싸고, 추가적인 관리 기능(replicas, selector)을 제공하는 구조입니다!

profile
bytebliss

0개의 댓글