Kubernetes job initcontainer

This model is mainly used for compilation, deployment, compilation and import

The init container can use git to download the code to emptydir, and then the main container builds it

apiVersion: batch/v1
kind: Job
metadata:
  generateName: test-
  namespace: default
spec:
  backoffLimit: 6
  completions: 1
  parallelism: 1
  template:
    spec:
      initContainers:
        - name: init
          image: ubuntu
          imagePullPolicy: IfNotPresent
          command: ["touch","/tmp/test.txt"]
          volumeMounts:
            - name: mytmp
              mountPath: "/tmp"
      containers: 
        - name: test
          image: ubuntu
          command: ["ls", "/tmp"]
          volumeMounts:
            - name: mytmp
              mountPath: "/tmp"
          imagePullPolicy: IfNotPresent
      dnsPolicy: ClusterFirst
      restartPolicy: Never
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - name: mytmp
        emptyDir: {}
Send a Message