使用file-store作为卷在GKE集群上部署elasticsearch

fslejnso  于 2023-10-17  发布在  ElasticSearch
关注(0)|答案(1)|浏览(122)

下面是我使用的menifest文件

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch
  labels:
    service: elasticsearch
spec:
  serviceName: es
  replicas: 1
  selector:
    matchLabels:
      service: elasticsearch
  template:
    metadata:
      labels:
        service: elasticsearch
    spec:
      terminationGracePeriodSeconds: 300
      initContainers:
      - name: fix-the-volume-permission
        image: busybox
        command:
        - sh
        - -c
        - chown -R 1000:1000 /usr/share/elasticsearch/data
        securityContext:
          privileged: true
        volumeMounts:
        - name: podpvc
          mountPath: /usr/share/elasticsearch/data
      - name: increase-the-vm-max-map-count
        image: busybox
        command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        securityContext:
          privileged: true
      - name: increase-the-ulimit
        image: busybox
        command:
        - sh
        - -c
        - ulimit -n 65536
        securityContext:
          privileged: true
      containers:
      - name: elasticsearch
        image: docker.elastic.co/elasticsearch/elasticsearch:7.17.8
        ports:
        - containerPort: 9200
          name: http
        - containerPort: 9300
          name: tcp
        resources:
          requests:
            memory: 2Gi
            cpu: 1
          limits:
            memory: 4Gi
            cpu: 2
        env:
          - name: cluster.name
            value: elastic-cluster
          - name: node.name
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: discovery.zen.ping.unicast.hosts
            value: "elastic-0.es.default.svc.cluster.local,elastic-1.es.default.svc.cluster.local,elastic-2.es.default.svc.cluster.local,elastic-3.es.default.svc.cluster.local,elastic-4.es.default.svc.cluster.local"
          - name: ES_JAVA_OPTS
            value: -Xms2g -Xmx4g
          # - name: ES_PROTOCOL  
          #   value: http
          - name: discovery.type
            value: single-node
          - name: XPACK_LICENSE_SELF_GENERATED_TYPE
            value: basic
          - name: xpack.security.enabled
            value: 'false'
          - name: xpack.monitoring.enabled
            value: 'false'
        volumeMounts:
        - name: podpvc
          mountPath: /usr/share/elasticsearch/data
  volumeClaimTemplates:
  - metadata:
      name: podpvc
    spec:
      accessModes:
        - ReadWriteMany
      storageClassName: filestore-sc
      volumeName: elastic
      resources:
        requests:
          storage: 1Ti

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: elastic
spec:
  storageClassName: "filestore-sc"
  capacity:
    storage: 1Ti
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  volumeMode: Filesystem
  csi:
    driver: filestore.csi.storage.gke.io
    volumeHandle: "modeInstance/zone-xx/name-xx/elastic"
    volumeAttributes:
      ip: xx.xx.xx.xx
      volume: elastic

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: filestore-sc
provisioner: filestore.csi.storage.gke.io
volumeBindingMode: Immediate
allowVolumeExpansion: true
parameters:
  tier: enterprise
  network: default

---
apiVersion: v1
kind: Service
metadata:
  name: es
  labels:
    service: elasticsearch
spec:
  selector:
    service: elasticsearch
  ports:
  - port: 9200
    name: serving
  - port: 9300
    name: node-to-node
  type: LoadBalancer

我在pod上初始化Elasticsearch时收到下面的错误,pod发出错误crashBackLoop。
java.lang.IllegalStateException:无法获取节点锁,尝试/usr/share/elasticsearch/data,锁ID为[0];可能这些位置不可写,或者在未增加[node. max_local_storage_nodes](was [1])的情况下启动了多个节点?在org.elasticsearch.env.NodeEnvironment。(NodeEnvironment.java:328)at org.elasticsearch.node.Node.(Node.java:429)在org.elasticsearch.node.Node。(Node.java:309)at org.elasticsearch.bootstrap.Bootstrap$5.(Bootstrap.java:234)at org. elasticsearch。自助引导。在org上设置(Bootstrap.java:234)。elasticsearch。自助引导。init(Bootstrap.java:434)at org. elasticsearch。自助ElasticSearch init(Elasticsearch.java:169)at org. elasticsearch。自助ElasticSearch execute(Elasticsearch.java:160)at org. elasticsearch。EnvironmentAwareCommand.在org上执行(EnvironmentAwareCommand.java:77)。elasticsearch。指挥。mainWithoutErrorHandling(Command.java:112)at org. elasticsearch。指挥。main(Command.java:77)at org. elasticsearch。自助ElasticSearch main(Elasticsearch.java:125)at org. elasticsearch。自助ElasticSearch main(Elasticsearch.java:80)

3b6akqbq

3b6akqbq1#

我通过在init容器中设置runAsUser: 0来使它工作。

initContainers:
    - name: sysctl
      securityContext:
        privileged: true
        runAsUser: 0
      command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']

相关问题