본문으로 건너뛰기

11.4 선언적 hibernation

Hibernation은 클러스터를 통째로 재우는 기능이다. Pod를 모두 내려 CPU·메모리를 반납하되, 데이터가 담긴 PVC는 그대로 보존한다. 배치성 워크로드처럼 특정 시간에만 데이터베이스가 필요하고 나머지 시간에는 놀리는 경우, 그 유휴 시간의 컴퓨트 비용을 아끼는 것이 목적이다. fencing(11.3)이 postgres만 멈추고 Pod는 살려 두는 것과 달리, hibernation은 Pod 자체를 없앤다.

    flowchart TD
  RUN["running<br/>Pod + PVC"] -->|hibernation on| STOP["primary 먼저<br/>내림"]
  STOP --> REP["replica들 내림"]
  REP --> HIB["hibernated<br/>Pod 없음, PVC 유지"]
  HIB -->|hibernation off| WAKE["Pod 재생성"]
  WAKE --> RUN

  classDef node fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
  class RUN,STOP,REP,HIB,WAKE node
  

재울 때 무슨 일이 일어나는가

hibernation을 켜면 Operator는 primary Pod를 먼저 내리고, 그다음 replica Pod들을 내린다. 이 순서는 마지막에 switchover가 일어나지 않게 해 replica의 동기 상태를 그대로 보존하기 위한 것이다. 완료되면 클러스터에는 running Pod가 하나도 없고, PVC만 남아 다음 기동을 기다린다.

재우기: annotation

cnpg.io/hibernation annotation을 on으로 준다.

kubectl annotate cluster <cluster-name> --overwrite \
  cnpg.io/hibernation=on

상태 확인

hibernation은 클러스터 상태의 condition으로 확인한다.

kubectl get cluster <cluster-name> \
  -o "jsonpath={.status.conditions[?(.type==\"cnpg.io/hibernation\")]}"

플러그인을 쓰면 전체 상태와 함께 볼 수 있다.

kubectl cnpg status <cluster-name>

깨우기

annotation을 off로 바꾸거나 아예 제거하면 Operator가 Pod를 다시 만들고 정상 운영으로 돌아온다.

# off로 전환
kubectl annotate cluster <cluster-name> --overwrite \
  cnpg.io/hibernation=off

# annotation 제거
kubectl annotate cluster <cluster-name> cnpg.io/hibernation-

플러그인으로

cnpg 플러그인의 hibernate 서브커맨드가 위 annotation 조작을 감싼다.

kubectl cnpg hibernate on <cluster-name>    # 재우기
kubectl cnpg hibernate off <cluster-name>   # 깨우기
hibernation은 데이터(PVC)를 지운 것이 아니라 컴퓨트만 반납한 상태다. PVC는 그대로 남아 비용이 발생하므로, “비용 절감"은 어디까지나 CPU·메모리 몫이다. 완전히 리소스를 회수하려면 백업을 확인한 뒤 클러스터를 삭제해야 하고, 이는 hibernation과 다른 조치다.

fencing과의 차이

구분fencinghibernation
대상인스턴스 단위 선택 가능클러스터 전체
Pod유지 (Ready 아님)제거
postgres중지중지
절감 자원없음 (Pod 유지)컴퓨트(CPU·메모리)
주 용도문제 인스턴스 조사유휴 기간 비용 절감

정리

  • hibernation = Pod 전부 내리고 PVC는 보존 → 유휴 컴퓨트 비용 절감
  • 재울 때 primary→replica 순으로 내려 동기 상태 유지
  • annotation cnpg.io/hibernation=on|off 또는 cnpg hibernate on/off
  • 상태는 cnpg.io/hibernation condition 또는 cnpg status로 확인
  • PVC는 남으므로 스토리지 비용은 계속 발생 — 완전 회수는 클러스터 삭제와 별개

이것으로 Part XI를 마친다. 다음 Part(XII)에서는 logical replication·PostGIS 같은 확장 주제를 다룬다.