티스토리 뷰

문제

Cluster: kubectl config use-context k8s
  • Perform the following
  • Tasks:
    • Add an init container to web-pod(which has been defined in spec file /data/cka/webpod.yaml).
    • The init container should create an empty file named /workdir/data.txt
    • If /workdir/data.txt is not detected, the Pod should exit.
    • Once the spec file has been updated with the init container definition, the Pod should be created

문제 환경 구성 

#/data/cka/webpod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: web-pod
spec:
  containers:
  - image: busybox:1.28
    name: main
    command: ['sh','-c','if [ !-f /workdir/data.txt ];then exit 1;else sleep 300;fi']
    volumeMounts:
    - mountPath: "/workdir"
      name: workdir
  volumes:
  - name: workdir
    emptyDir: {}

문제풀이

# 1.webpod.yaml 수정
vim /data/cka/webpod.yaml

....
apiVersion: v1
kind: Pod
metadata:
  name: web-pod
spec:
  containers:
  - image: busybox:1.28
    name: main
    command: ['sh','-c','if [ !-f /workdir/data.txt ];then exit 1;else sleep 300;fi']
    volumeMounts:
    - mountPath: "/workdir"
      name: workdir
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh','-c','touch /workdir/data.txt']
    volumeMounts:
    - mountPath: "/workdir"
      name: workdir
  volumes:
  - name: workdir
    emptyDir: {}
    
 # 2. pod 업데이트 하기
 kubectl apply -f /data/cka/webpod.yaml
 

Init Containers

This page provides an overview of init containers: specialized containers that run before app containers in a Pod. Init containers can contain utilities or setup scripts not present in an app image. You can specify init containers in the Pod specification

kubernetes.io

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/09   »
일 월 화 수 목 금 토
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함