[CKA] init container

Hi yena·2023년 2월 27일
0

CKA

목록 보기
1/4

참고 : https://kubernetes.io/ko/docs/concepts/workloads/pods/init-containers/

CKA 시험문제중 빈출문제인 init container
메인 컨테이너가 실행되기 이전 초기화 컨테이너이다.
멀티컨테이너 처럼 여러개 붙일 수 있으며
항상 완료를 목표로 실행된다(무한대로 반복..)
각 init container는 다음 컨테이너가 실행되기 전에 완벽하게 실행되어야 한다.

CKA에 나오는 문제 형식은 /tmp/initcontainer.yaml 파일에 init 컨테이너를 추가해라. -> init container 은 /workdir/calm.txt를 생성해야하며 만약 /workdir/calm.txt가 없다면 /tmp/initcontainer.yaml 파일에 정의하여 생성하도록 해라. 이런식이다.

위와 같은 문제가 나온다면 /tmp/initcontainer.yaml 에다가
init container 를 추가해주고, command를 조절해주면 해결된다

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
spec:
  volumes: 
  - name: workdir
    emptyDir: 
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'if [ -f /workdir/calm.txt]; then sleep 100000; else exit 1; fi']
    volumeMounts: 
    - name: workdir
      mountPath: /workdir
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "touch /workdir/calm.txt"]
    volumeMounts:
    - name: workdir
      mountPath: /workdir

0개의 댓글