# DeploymentConfig for starting up the random-generator
apiVersion: apps/v1
kind: Deployment
metadata:
  name: random-generator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: random-generator
  template:
    metadata:
      labels:
        app: random-generator
    spec:
      initContainers:
      # Same image as main container, but used for calling the batch CLI
      - image: k8spatterns/random-generator:1.0
        name: init
        command:
        - java
        # Use / as classpath to pick up the class file
        - -classpath
        - /
        # Class running batch job
        - RandomRunner
        # 1. Arg: File to store data (on a PV)
        - /logs/random.log
        # 2. How many iterations
        - "100000"
        # Shared volume with main container. Use for initializing the batch file
        volumeMounts:
        - mountPath: /logs
          name: log-volume
      containers:
      # ------------------------------------------------
      # Main container sharing the /logs dir with the init container
      - image: k8spatterns/random-generator:1.0
        name: random-generator
        env:
        # The log file that we want to export
        - name: LOG_FILE
          value: /logs/random.log
        ports:
        # Application running on port 8080
        - containerPort: 8080
          protocol: TCP
        volumeMounts:
        - mountPath: /logs
          name: log-volume
      volumes:
      # New empty directory volume for sharing the log file between container
      - name: log-volume
        emptyDir: {}
