지니데비 기록 자세히보기

데브옵스/Orchestration

[Kubernetes] 31. InitContainers

지니데비 2024. 12. 5. 17:17
728x90

Init Container는 메인 컨테이너를 실행하기 전에 먼저 실행되는 컨테이너로, 실행 전 사전작업(설정, 데이터 다운로드, 실행환경 준비 등)을 수행한다. Init Container를 Multi로 구성할 경우, 파일에 정의된 순서대로 실행된다. 모든 컨테이너가 실행 성공할 때까지 다시 실행되며, 초기화 작업이 모두 성공하면 Init Container는 종료되고 메인 컨테이너를 실행한다.

Init Container 예시
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox
    command: ['sh', '-c', 'git clone <some-repository-that-will-be-used-by-application> ; done;']
Init Container 예시 - Multi
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']

 

728x90
반응형

'데브옵스 > Orchestration' 카테고리의 다른 글

[Kubernetes] 33. OS Upgrades  (0) 2025.01.08
[Kubernetes] 32. Self Healing Application  (0) 2025.01.08
[Kubernetes] 30. Multi-Container  (0) 2024.12.05
[Kubernetes] 29. Encrypt Secret  (0) 2024.12.05
[Kubernetes] 28. Secret  (0) 2024.12.05