Exercise 4.6: Simple initContainer

  1. Pod 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: init-tester
    spec:
      containers:
      - name: webservice
        image: nginx
      initContainers:
      - name: failed
        image: busybox
        command: [/bin/false]
    EOF
  2. Pod 상태 추적

    kubectl get pod init-tester -w
  3. Ctrl+C 입력

  4. Pod 상세내용 확인

    kubectl describe pod init-tester
  5. Pod 삭제

    kubectl delete pod init-tester
  6. Pod 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx-init
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - name: html
          mountPath: /usr/share/nginx/html
      initContainers:
      - name: index
        image: curlimages/curl
        command:
          - "sh"
          - "-c"
          - "echo Welcome to LFD459 > /data/index.html"
        volumeMounts:
        - name: html
          mountPath: /data
      volumes:
      - name: html
        emptyDir: {}
    EOF
  7. Pod 상태 확인

    kubectl get pod nginx-init
  8. Pod 상세내용 확인

    kubectl describe pod nginx-init
  9. CURL 명령어를 통해서 생성된 Pod의 IP주소로 HTTP 요청

    curl $(kubectl get pod nginx-init -o=jsonpath='{.status.podIP}')
  10. Pod 삭제

    kubectl delete pod nginx-init

Last updated