How can i creat pod with out this error elasticsearch on kubernetes

8/30/2019

I want to create elasticsearch pod on kubernetes.

I make some config change to edit path.data and path.logs

But I'm getting this error.

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

service-account.yml

apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch

es-svc.yml

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

elasticsearch.yml

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

es-deploy.yml

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

1 Answer

8/30/2019

There is syntax problem in your es-deploy.yaml file.

This should work.

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

The volumes section is not under containers section, it should be under spec section as the error suggest.

You can validate your k8s yaml files for syntax error online using this site.

Hope this helps.

-- mchawre
Source: StackOverflow