Pod - Init Container
목차
Application container이전에 실행되는 특수 컨테이너 → app.Container 실행환경 준비
다양한 목적으로 사용 가능하지만 Application container 가 원하는 방향으로 실행 될수 준비하는것이 주목적 →메인프로세스 환경의 초기화
App.Container 소스코드 변경 할 필요 없이 환경을 구성가능하게 함
Initial container 동작
- Pod에 관련된 모든 네트워킹 및 스트리지가 프로비저닝 된 후에 실행
- Pod의 initial container가 실피시 kublet은 성공 할 때 까지 init.Container를 반복적으로 재시작
- 단, Pod restartPolicy: Never가 지정되었을땐, init.Container가 실패하면 Kubernetes는 전체 Pod를 실패 처리 후 종료
Initial container 사례
- MSA 소스로부터 최신 구성 파일을 가져오는 작업 → App.Container는 항상 최신 구성이 가능 해짐
- DB init 또는 초기(기본) 데이터를 채우는 작업 구성(스키마 생성, 데이터 마이그레이션)을 처리하여 DB가 App.Container와 상호 작용 준비가 되었는지 확인 할 수 있음 → App.Container 경량화
Initial container 예시
- Local volume 영역을 생성
- Init.Container는 curl로 외부 리소스를 받아 해당데이터를 Local volume에 기록
- 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¤t_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/