카테고리 없음

[kubernetes] 무중단배포 예시(readinessProbe)

miracle21 2026. 1. 4. 18:56
반응형

 

 

전체 코드

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-deployment
  namespace: ns-service
spec:
  replicas: 20
  selector:
    matchLabels:
      app: service
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
  template:
    spec:
      containers:
      - name: service
        image: <image_name>
        ports:
        - containerPort: 8080
          protocol: TCP
        readinessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 60
          failureThreshold: 30

 

 

 

무중단 배포를 위해 추가한 부분

 

1. strategy.rollingUpdate 추가

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
  • maxSurge: 업데이트 중 기존 Replica 수보다 추가로 생성 가능한 Pod의 최대 수(또는 비율)을 지정
  • maxUnavailable: 업데이트 중 서비스 불가(Pod NotReady) 상태로 허용되는 최대 Pod 수(또는 비율)를 지정

maxSurge를 100%로 한 이유는, 20대의 pod가 하나씩 올라가고 내려가는 시간이 비효율적이라고 판단했다.

 

어차피 서비스가 완전히 올라가지 않으면 기존 pod 가 내려가지 않도록 maxUnavailable 를 0으로 설정했기에, 한 번에 모든 pod가 올라오도록 했다.

 

 

2. spec.containers.readinessProbe 추가

        readinessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 60
          failureThreshold: 30

 

  • tcpSocket.port: 지정한 포트(예: 8080)로 TCP 연결이 가능한지 확인
  • initialDelaySeconds: 컨테이너 시작 후 첫 Readiness 체크를 시작하기 전까지 기다리는 시간
  • periodSeconds: Readiness Probe를 주기적으로 실행하는 간격
  • failureThreshold: Probe가 연속으로 실패할 경우, 이 횟수 이상이면 Pod를 NotReady로 판단

 

 

 

readinessProbe컨테이너가 사용자 트래픽을 받을 준비가 되었는지 확인한다.

컨테이너가 정상적으로 실행 중인지 확인하는 livenessProbe컨테이너 상태를 확인하는 방식이 다르다.

 

livenessProbe 없이 readinessProbe만 쓴 이유는, 반드시 신규 pod가 health check 가 되어야 예전 pod 가 내려가야 했기 때문이다.

 

 

컨테이너 시작 10초 후부터 60초 간격으로 8080 포트 TCP 연결을 확인하며, 30번 연속 실패 시 Pod 를 NotReady 로 판단하도록 했다. 서비스가 정상적으로 올라가는데 10~20분 정도 소요가 되기에 간격을 크게 접았다.

반응형