How can I edit path.data and path.log for elasticsearch on Kubernetes?

8/30/2019

I made an es-deploy.yml file then I typed the path.log and path.data values.

After creating the pod, I checked that directory then there was nothing.

The setting did not work!

How can I edit path.data and path.log for elasticsearch on Kubernetes!

I also tried using PATH_DATA


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/
-- Jokky
elasticsearch
kubernetes

1 Answer

8/30/2019

Those values path.data and path.logs are not environment variables. They are config options.

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

You will have to create a ConfigMap containing your elasticsearch.yaml with something like this:

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

(Note that the above ConfigMap will also allow you to use the DATA_PATH environment variable)

Then mount your volumes in your Pod with something like this:

    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
    <add-whatever-volume-you-are-using-for-data>
-- Rico
Source: StackOverflow