如何在Kubernetes上的Elasticsearch中创建pod而不会出现此错误

muk1a3rh  于 11个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(97)

我想在Kubernetes上创建Elasticsearch pod。
我做了一些配置更改来编辑 * 路径.数据和路径.日志 *
但我得到了这个错误。
错误类型:验证“es-deploy.yml”时出错:验证数据时出错:ValidationError(Deployment.spec.template.spec.containers[0]):unknown field“volumes”in io.k8s.api.core.v1.Container;如果选择忽略这些错误,请使用--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

wgeznvg7

wgeznvg71#

您的es-deploy.yaml文件中存在语法问题。
这个应该能用

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

字符串
volumes部分不在containers部分之下,它应该像错误建议的那样在spec部分之下。
您可以使用this站点在线验证k8s yaml文件的语法错误。
希望这对你有帮助。

相关问题