목차

Pod - Init Container

  • Pod에 관련된 모든 네트워킹 및 스트리지가 프로비저닝 된 후에 실행
  • Pod의 initial container가 실피시 kublet은 성공 할 때 까지 init.Container를 반복적으로 재시작
  • 단, Pod restartPolicy: Never가 지정되었을땐, init.Container가 실패하면 Kubernetes는 전체 Pod를 실패 처리 후 종료
    1. MSA 소스로부터 최신 구성 파일을 가져오는 작업 → App.Container는 항상 최신 구성이 가능 해짐
    1. DB init 또는 초기(기본) 데이터를 채우는 작업 구성(스키마 생성, 데이터 마이그레이션)을 처리하여 DB가 App.Container와 상호 작용 준비가 되었는지 확인 할 수 있음 → App.Container 경량화
    1. Local volume 영역을 생성
    1. Init.Container는 curl로 외부 리소스를 받아 해당데이터를 Local volume에 기록
    1. App.Container는 시작과 함게 Local volume에서 필요한 데이터를 읽어 작동
apiVersion: v1
kind: Pod
metadata:
 name: weather-pod
 namespace: default
spec:
 volumes: #1
   - emptyDir: {}
     name: weather-data
 initContainers: #2
   - name: download-config
     image: curlimages/curl:7.85.0
     args: [\"https://api.open-meteo.com/v1/forecast?latitude=37.5443878&longitude=127.03744246&current_weather=true\", \"-o\", \"/usr/share/nginx/html/index.html\"]
     volumeMounts:
       - mountPath: /usr/share/nginx/html
         name: weather-data
 containers: #3
   - image: nginx:1.25.3-alpine
     name: nginx-container
     ports:
       - containerPort: 80
     volumeMounts:
       - mountPath: /usr/share/nginx/html
         name: weather-data

 #출처, https://velocity.tech/