{
  "apiVersion": "apps/v1beta1",
  "kind": "StatefulSet",
  "metadata": {
    "labels": {
      "app": "elasticsearch",
      "app.kubernetes.io/instance": "elasticsearch4",
      "chart": "elasticsearch-1.7.0",
      "component": "data",
      "heritage": "Tiller",
      "release": "elasticsearch4"
    },
    "name": "elasticsearch4-data"
  },
  "spec": {
    "replicas": 2,
    "selector": {
      "matchLabels": {
        "app": "elasticsearch",
        "component": "data",
        "release": "elasticsearch4"
      }
    },
    "serviceName": "elasticsearch4-data",
    "template": {
      "metadata": {
        "labels": {
          "app": "elasticsearch",
          "app.kubernetes.io/instance": "elasticsearch4",
          "component": "data",
          "release": "elasticsearch4"
        }
      },
      "spec": {
        "affinity": {
          "podAntiAffinity": {
            "preferredDuringSchedulingIgnoredDuringExecution": [
              {
                "podAffinityTerm": {
                  "labelSelector": {
                    "matchLabels": {
                      "app": "elasticsearch",
                      "component": "data",
                      "release": "elasticsearch4"
                    }
                  },
                  "topologyKey": "kubernetes.io/hostname"
                },
                "weight": 1
              }
            ]
          }
        },
        "containers": [
          {
            "env": [
              {
                "name": "DISCOVERY_SERVICE",
                "value": "elasticsearch4-discovery"
              },
              {
                "name": "NODE_MASTER",
                "value": "false"
              },
              {
                "name": "PROCESSORS",
                "valueFrom": {
                  "resourceFieldRef": {
                    "resource": "limits.cpu"
                  }
                }
              },
              {
                "name": "ES_JAVA_OPTS",
                "value": "-Djava.net.preferIPv4Stack=true -Xms1536m -Xmx1536m"
              },
              {
                "name": "MINIMUM_MASTER_NODES",
                "value": "2"
              }
            ],
            "image": "docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.0",
            "imagePullPolicy": "IfNotPresent",
            "lifecycle": {
              "postStart": {
                "exec": {
                  "command": [
                    "/bin/bash",
                    "/post-start-hook.sh"
                  ]
                }
              },
              "preStop": {
                "exec": {
                  "command": [
                    "/bin/bash",
                    "/pre-stop-hook.sh"
                  ]
                }
              }
            },
            "name": "elasticsearch",
            "ports": [
              {
                "containerPort": 9300,
                "name": "transport"
              }
            ],
            "readinessProbe": {
              "httpGet": {
                "path": "/_cluster/health?local=true",
                "port": 9200
              },
              "initialDelaySeconds": 5
            },
            "resources": {
              "limits": {
                "cpu": "1"
              },
              "requests": {
                "cpu": "25m",
                "memory": "1536Mi"
              }
            },
            "volumeMounts": [
              {
                "mountPath": "/usr/share/elasticsearch/data",
                "name": "data"
              },
              {
                "mountPath": "/usr/share/elasticsearch/config/elasticsearch.yml",
                "name": "config",
                "subPath": "elasticsearch.yml"
              },
              {
                "mountPath": "/pre-stop-hook.sh",
                "name": "config",
                "subPath": "pre-stop-hook.sh"
              },
              {
                "mountPath": "/post-start-hook.sh",
                "name": "config",
                "subPath": "post-start-hook.sh"
              }
            ]
          }
        ],
        "initContainers": [
          {
            "command": [
              "sysctl",
              "-w",
              "vm.max_map_count=262144"
            ],
            "image": "busybox",
            "imagePullPolicy": "Always",
            "name": "sysctl",
            "securityContext": {
              "privileged": true
            }
          },
          {
            "command": [
              "/bin/bash",
              "-c",
              "chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data && chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/logs"
            ],
            "image": "docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.0",
            "imagePullPolicy": "IfNotPresent",
            "name": "chown",
            "securityContext": {
              "runAsUser": 0
            },
            "volumeMounts": [
              {
                "mountPath": "/usr/share/elasticsearch/data",
                "name": "data"
              }
            ]
          }
        ],
        "securityContext": {
          "fsGroup": 1000
        },
        "terminationGracePeriodSeconds": 3600,
        "volumes": [
          {
            "configMap": {
              "name": "elasticsearch4"
            },
            "name": "config"
          }
        ]
      }
    },
    "updateStrategy": {
      "type": "OnDelete"
    },
    "volumeClaimTemplates": [
      {
        "metadata": {
          "name": "data"
        },
        "spec": {
          "accessModes": [
            "ReadWriteOnce"
          ],
          "resources": {
            "requests": {
              "storage": "30Gi"
            }
          }
        }
      }
    ]
  }
}