<p>I made an <code>es-deploy.yml</code> file then I typed the <code>path.log</code> and <code>path.data</code> values.</p>

<p>After creating the pod, I checked that directory then there was nothing.</p>

<p>The setting did not work!</p>

<p>How can I edit <code>path.data</code> and <code>path.log</code> for elasticsearch on Kubernetes!</p>

<p>I also tried using PATH_DATA</p>

<hr>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: es
  labels:
    component: elasticsearch
spec:
  replicas: 1
  template:
    metadata:
      labels:
        component: elasticsearch
    spec:
      serviceAccount: elasticsearch
      initContainers:
        - name: init-sysctl
          image: busybox
          imagePullPolicy: IfNotPresent
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          securityContext:
            privileged: true
      containers:
        - name: es
          securityContext:
            capabilities:
              add:
                - IPC_LOCK
          image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: "CLUSTER_NAME"
              value: "myesdb"
            - name: "DISCOVERY_SERVICE"
              value: "elasticsearch"
            - name: NODE_MASTER
              value: "true"
            - name: NODE_DATA
              value: "true"
            - name: HTTP_ENABLE
              value: "true"
            - name: ES_JAVA_OPTS
              value: "-Xms256m -Xmx256m"
            - name: "path.data"
              value: "/data/elk/data"
            - name: "path.logs"
              value: "/data/elk/log"
          ports:
            - containerPort: 9200
              name: http
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
          volumeMounts:
            - mountPath: /data/elk/
</code></pre>

<p>Those values <code>path.data</code> and <code>path.logs</code> are not environment variables. They are <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#_config_file_format" rel="nofollow noreferrer">config options</a>. </p>

<p>The default <code>path.data</code> for the official elasticsearch image is <code>/usr/share/elasticsearch/data</code> based on the default value of <code>ES_HOME=/usr/share/elasticsearch/</code> If you don't want to use that path you have to override it in the <code>elasticsearch.yaml</code> config.</p>

<p>You will have to create a <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">ConfigMap</a> containing your <code>elasticsearch.yaml</code> with something like this:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-config
  namespace: es
data:
  elasticsearch.yml: |
    cluster:
      name: ${CLUSTER_NAME:elasticsearch-default}

    node:
      master: ${NODE_MASTER:true}
      data: ${NODE_DATA:true}
      name: ${NODE_NAME}
      ingest: ${NODE_INGEST:true}
      max_local_storage_nodes: ${MAX_LOCAL_STORAGE_NODES:1}

    processors: ${PROCESSORS:1}

    network.host: ${NETWORK_HOST:_site_}

    path:
      data: ${DATA_PATH:"/data/elk"}
      repo: ${REPO_LOCATIONS:[]}

    bootstrap:
      memory_lock: ${MEMORY_LOCK:false}

    http:
      enabled: ${HTTP_ENABLE:true}
      compression: true
      cors:
        enabled: true
        allow-origin: "*"

    discovery:
      zen:
        ping.unicast.hosts: ${DISCOVERY_SERVICE:elasticsearch-discovery}
        minimum_master_nodes: ${NUMBER_OF_MASTERS:1}

    xpack:
      license.self_generated.type: basic
</code></pre>

<p>(Note that the above ConfigMap will also allow you to use the <code>DATA_PATH</code> environment variable)</p>

<p>Then mount your volumes in your Pod with something like this:</p>

<pre><code>    volumeMounts:
        - name: storage
          mountPath: /data/elk
        - name: config-volume
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml

  volumes:
  - name: config-volume
    configMap:
      name: elasticsearch-config
  - name: storage
    &lt;add-whatever-volume-you-are-using-for-data&gt;
</code></pre>
