​​​​​原始command-job文件

  • apiVersion: batch/v1
    kind: Job
    metadata:
      name: command-job
    spec:
      template:
        spec:
          containers:
          - name: command-job
            image: busybox
            command: ["/bin/sh","-c","sleep 100;echo 'job one'"]
          restartPolicy: Never
  • kubernetes 中的已知job或pod的yaml配置文件导出
  • kubectl get job -n命名空间 job名 -o yaml >expory_job.yaml
    eg: kubectl  get job -n default command-job -o yaml  >export_cmd.yaml

    导出的yaml内容

  • apiVersion: batch/v1
    kind: Job
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"command-job","namespace":"default"},"spec":{"backoffLimit":6,"completionMode":"NonIndexed","completions":1,"parallelism":1,"suspend":false,"template":{"metadata":{"creationTimestamp":null,"labels":{"job-name":"command-job"}},"spec":{"containers":[{"command":["/bin/sh","-c","sleep 100;echo 'job one'"],"image":"busybox","imagePullPolicy":"Always","name":"command-job","resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File"}],"dnsPolicy":"ClusterFirst","restartPolicy":"Never","schedulerName":"default-scheduler","securityContext":{},"terminationGracePeriodSeconds":30}}}}
      creationTimestamp: "2023-03-31T12:57:31Z"
      generation: 1
      labels:
        controller-uid: fe93eb9a-374d-46f4-be7b-5d180d373925
        job-name: command-job
      name: command-job
      namespace: default
      resourceVersion: "156649"
      uid: fe93eb9a-374d-46f4-be7b-5d180d373925
    spec:
      backoffLimit: 6
      completionMode: NonIndexed
      completions: 1
      parallelism: 1
      selector:
        matchLabels:
          controller-uid: fe93eb9a-374d-46f4-be7b-5d180d373925
      suspend: false
      template:
        metadata:
          creationTimestamp: null
          labels:
            controller-uid: fe93eb9a-374d-46f4-be7b-5d180d373925
            job-name: command-job
        spec:
          containers:
          - command:
            - /bin/sh
            - -c
            - sleep 100;echo 'job one'
            image: busybox
            imagePullPolicy: Always
            name: command-job
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
    status:
      completionTime: "2023-03-31T12:59:33Z"
      conditions:
      - lastProbeTime: "2023-03-31T12:59:33Z"
        lastTransitionTime: "2023-03-31T12:59:33Z"
        status: "True"
        type: Complete
      ready: 0
      startTime: "2023-03-31T12:57:31Z"
      succeeded: 1
  • 删除后的yaml
  • apiVersion: batch/v1
    kind: Job
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"command-job","namespace":"default"},"spec":{"backoffLimit":6,"completionMode":"NonIndexed","completions":1,"parallelism":1,"suspend":false,"template":{"metadata":{"creationTimestamp":null,"labels":{"job-name":"command-job"}},"spec":{"containers":[{"command":["/bin/sh","-c","sleep 100;echo 'job one'"],"image":"busybox","imagePullPolicy":"Always","name":"command-job","resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File"}],"dnsPolicy":"ClusterFirst","restartPolicy":"Never","schedulerName":"default-scheduler","securityContext":{},"terminationGracePeriodSeconds":30}}}}
      generation: 1
      name: command-job
      namespace: default
      resourceVersion: "156649"
    spec:
      backoffLimit: 6
      completionMode: NonIndexed
      completions: 1
      parallelism: 1
      suspend: false
      template:
        spec:
          containers:
          - command:
            - /bin/sh
            - -c
            - sleep 100;echo 'job one'
            image: busybox
            imagePullPolicy: Always
            name: command-job
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30

    运行处理后的job

  • kubectl apply -f xxxx.yaml

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐