Skip to content

Instantly share code, notes, and snippets.

@ianychoi
Created July 14, 2021 13:31
Show Gist options
  • Select an option

  • Save ianychoi/7352dfdd2c0997e21bc53efb5027124c to your computer and use it in GitHub Desktop.

Select an option

Save ianychoi/7352dfdd2c0997e21bc53efb5027124c to your computer and use it in GitHub Desktop.
쿠버네티스 - Pod 단계 및 컨테이너 상태
  • completed.yaml : sleep 5초 후 종료 코드 0 반환 후 종료

    apiVersion: v1
    kind: Pod
    metadata:
      name: completed-pod
    spec:
      containers:
        - name: completed-pod
          image: busybox
          command: ["sh"]
          args: ["-c", "sleep 5 && exit 0"]
  • 생성 및 확인

    # 생성 후 파드 상태 확인
    curl -s -O https://raw.githubusercontent.com/gasida/DKOS/main/3/completed.yaml
    kubectl apply -f completed.yaml && kubectl get pod -w
    watch -d "kubectl describe pod completed-pod | grep Events -A 12"
    
    # 파드 restartPolicy 정책 확인
    kubectl get pod completed-pod -o yaml | grep restartPolicy
        restartPolicy: Always
    
    # 다음 실습을 위해서 생성된 파드 삭제
    kubectl delete pod --all
  • onfailure.yaml : restartPolicy: OnFailure, sleep 5초 후 종료 코드 1 반환 후 종료

    apiVersion: v1
    kind: Pod
    metadata:
      name: completed-pod
    spec:
      restartPolicy: OnFailure
      containers:
        - name: completed-pod
          image: busybox
          command: ["sh"]
          args: ["-c", "sleep 5 && exit 1"]
  • 생성 및 확인

    # 생성 후 파드 상태 확인
    curl -s -O https://raw.githubusercontent.com/gasida/DKOS/main/3/onfailure.yaml
    kubectl apply -f onfailure.yaml && kubectl get pod -w
    watch -d "kubectl describe pod completed-pod | grep Events -A 12"
    
    # 다음 실습을 위해서 생성된 파드 삭제
    kubectl delete pod --all
  • onfailure.yaml : restartPolicy: OnFailure, sleep 5초 후 종료 코드 0 반환 후 종료

    apiVersion: v1
    kind: Pod
    metadata:
      name: completed-pod
    spec:
      restartPolicy: OnFailure
      containers:
        - name: completed-pod
          image: busybox
          command: ["sh"]
          args: ["-c", "sleep 5 && exit 0"]
  • 생성 및 확인

    # 생성 후 파드 상태 확인
    cat << EOF | kubectl apply -f - && kubectl get pod -w
    apiVersion: v1 
    kind: Pod
    metadata:
      name: completed-pod
    spec:
      restartPolicy: OnFailure
      containers:
        - name: completed-pod
          image: busybox
          command: ["sh"]
          args: ["-c", "sleep 5 && exit 0"]
    EOF
    watch -d "kubectl describe pod completed-pod | grep Events -A 12"
    
    # 다음 실습을 위해서 생성된 파드 삭제
    kubectl delete pod --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment