<p>I want to create elasticsearch pod on kubernetes.</p>

<p>I make some config change to edit <strong><em>path.data and path.logs</em></strong></p>

<p>But I'm getting this error.</p>

<blockquote>
  <p>error: error validating "es-deploy.yml": error validating data:
  ValidationError(Deployment.spec.template.spec.containers[0]): unknown
  field "volumes" in io.k8s.api.core.v1.Container; if you choose to
  ignore these errors, turn validation off with --validate=false</p>
</blockquote>

<p>service-account.yml</p>

<pre><code>apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch
</code></pre>

<hr>

<p>es-svc.yml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
component: elasticsearch
spec:
# type: LoadBalancer
selector:
component: elasticsearch
ports:
- name: http
port: 9200
protocol: TCP
- name: transport
port: 9300
protocol: TCP
</code></pre>

<hr>

<p>elasticsearch.yml</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-config
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>

<hr>

<p>es-deploy.yml</p>

<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: "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"
          ports:
            - containerPort: 9200
              name: http
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
          volumeMounts:
           - name: storage
             mountPath: /data/elk
           - name: config-volume
             mountPath: /usr/share/elasticsearch/elastic.yaml
          volumes:
            - name: storage
              emptyDir: {}
            - name: config-volume
              configMap:
                name: elasticsearch-config
</code></pre>

Jokky
<p>There is syntax problem in your <code>es-deploy.yaml</code> file.</p>

<p>This should work.</p>

<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: "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"
          ports:
            - containerPort: 9200
              name: http
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
          volumeMounts:
           - name: storage
             mountPath: /data/elk
           - name: config-volume
             mountPath: /usr/share/elasticsearch/elastic.yaml
      volumes:
        - name: storage
          emptyDir: {}
        - name: config-volume
          configMap:
            name: elasticsearch-config
</code></pre>

<p>The <code>volumes</code> section is not under <code>containers</code> section, it should be under <code>spec</code> section as the error suggest.</p>

<p>You can validate your k8s yaml files for syntax error online using <a href="https://kubeyaml.com/" rel="nofollow noreferrer">this</a> site.</p>

<p>Hope this helps.</p>
