실습

Job

  1. Job 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: sleepy
    spec:
      template:
        spec:
          containers:
          - name: resting
            image: busybox
            command: ["/bin/sleep"]
            args: ["3"]
          restartPolicy: Never
    EOF
  2. 생성된 Job 상태 확인

    kubectl get job sleepy
  3. Job에 발생한 Event 확인

    kubectl describe job sleepy
  4. 생성된 Pod 확인

    kubectl get pod -l job-name=sleepy
  5. 생성된 Job의 Manifest를 YAML 형식으로 출력

    kubectl get job sleepy -o yaml | grep -A 14 -B 1 ^spec
  6. Job 삭제

    kubectl delete job sleepy
  7. Job 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: sleepy
    spec:
      completions: 5
      template:
        spec:
          containers:
          - name: resting
            image: busybox
            command: ["/bin/sleep"]
            args: ["3"]
          restartPolicy: Never
    EOF
  8. 생성된 Job 상태 확인

    kubectl get job sleepy
  9. 생성된 Pod 확인

    kubectl get pod -l job-name=sleepy
  10. Job 삭제

    kubectl delete job sleepy
  11. Job 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: sleepy
    spec:
      completions: 5
      parallelism: 2
      template:
        spec:
          containers:
          - name: resting
            image: busybox
            command: ["/bin/sleep"]
            args: ["3"]
          restartPolicy: Never
    EOF
  12. 생성된 Job 상태 확인

    kubectl get job sleepy
  13. 생성된 Pod 확인

    kubectl get pod -l job-name=sleepy
  14. Job 삭제

    kubectl delete job sleepy
  15. Job 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: sleepy
    spec:
      completions: 5
      parallelism: 2
      activeDeadlineSeconds: 15
      template:
        spec:
          containers:
          - name: resting
            image: busybox
            command: ["/bin/sleep"]
            args: ["5"]
          restartPolicy: Never
    EOF
  16. 생성된 Job 상태 확인

    kubectl get job sleepy
  17. 생성된 Pod 확인

    kubectl get pod -l job-name=sleepy
  18. Job에 발생한 Event 확인

    kubectl describe job sleepy
  19. Job 삭제

    kubectl delete job sleepy

CronJob

  1. CronJob 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
      name: sleepy
    spec:
      schedule: "*/1 * * * *"
      jobTemplate:
        spec:
          template:
            spec:          
              containers:
              - name: resting
                image: busybox
                command: ["/bin/sleep"]
                args: ["5"]
              restartPolicy: Never
    EOF
  2. 생성된 CronJob 상태 확인

    kubectl get cronjob sleepy
  3. Job 목록 확인

    kubectl get job
  4. Pod 목록 확인

    kubectl get pod -l job-name
  5. CronJob 삭제

    kubectl delete cronjob sleepy
  6. CronJob 생성

    cat <<EOF | kubectl create -f -
    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: sleepy
    spec:
      schedule: "*/1 * * * *"
      jobTemplate:
        spec:
          template:
            spec:
              activeDeadlineSeconds: 10          
              containers:
              - name: resting
                image: busybox
                command: ["/bin/sleep"]
                args: ["30"]
              restartPolicy: Never
    EOF
  7. 생성된 CronJob 상태 확인

    kubectl get cronjob sleepy
  8. Job 목록 확인

    kubectl get job
  9. Pod 목록 확인

    kubectl get pod -l job-name
  10. CronJob 삭제

    kubectl delete cronjob sleepy

Last updated