apiVersion: apps/v1
kind: Deployment
metadata:
  name: elastic5
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elastic5
  template:
    metadata:
      labels:
        app: elastic5
    spec:
      containers:
      - name: elastic5
        image: gcr.io/advance-anvil-247513/elastic5
        ports:
        - containerPort: 9200
        - containerPort: 9300
        env:
          - name: ES_JAVA_OPTS
            value: "-Xmx512m -Xms512m"
        resources:
          limits:
            cpu: 200m
            memory: 2048Mi
          requests:
            cpu: 50m
            memory: 900Mi
        volumeMounts:
          - mountPath: /usr/share/elasticsearch/data
            name: nfs-drive
            subPath: es5_data
          - mountPath: /usr/share/elasticsearch/config
            name: nfs-drive
            subPath: es5_config
      initContainers:
        - name: sysctl
          image: busybox:1.27.2
          securityContext:
            privileged: true
          command: ['sh', '-c']
          args: ['sysctl -w vm.max_map_count=262144',
                 'chmod -R 777 "/usr/share/elasticsearch/data"',
#                 'chmod -R 777 "/usr/share/elasticsearch/config"'
          ]
#          // FIRST NEED TO GET THE ORIGINAL DATA FORM THE FOLDERS AND COPY IT TO data2 and config2, then revert to data and config
          volumeMounts:
            - mountPath: /usr/share/elasticsearch/data
              name: nfs-drive
              subPath: es5_data
#            - mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
#              name: nfs-drive
#              subPath: es5_config/elasticsearch.yml
      volumes:
        - name: nfs-drive
          persistentVolumeClaim:
            claimName: nfs-drive-pvc2
