如何在 Kubernete 副本集中部署 Elasticsearch 集群?

时间:2021-06-30 00:41:49

标签: elasticsearch kubernetes

我正在尝试将 Elasticsearch 搜索部署到 K8S 集群。下面是我的配置。它适用于 replicas: 1。但是如果我将其更改为大于 1 的值,则会在 K8S 集群中部署多个 pod。但是如何让它们作为一个 Elasticsearch 集群节点一起工作?

我知道我可以使用 API 在 Elasticsearch 集群中手动添加节点。但是有没有办法让集群自动发现额外的节点?

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es
  namespace: default
spec:
  serviceName: es-entrypoint
  replicas: 1
  selector:
    matchLabels:
      name: es
  template:
    metadata:
      labels:
        name: es
    spec:
      volumes:
        - name: es-config
          configMap:
            name: es-config
            items:
              - key: elasticsearch.yml
                path: elasticsearch.yml
        - name: persistent-storage
          persistentVolumeClaim:
            claimName: es-claim
      initContainers:
        - name: permissions-fix
          image: busybox
          volumeMounts:
            - name: persistent-storage
              mountPath: /usr/share/elasticsearch/data
          command: [ 'chown' ]
          args: [ '1000:1000', '/usr/share/elasticsearch/data' ]
      containers:
        - name: es
          image: elasticsearch:7.10.1
          resources:
            requests:
              cpu: 2
              memory: 8
          ports:
            - name: http
              containerPort: 9200
            - containerPort: 9300
              name: inter-node
          volumeMounts:
            - name: es-config
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              subPath: elasticsearch.yml
            - name: persistent-storage
              mountPath: /usr/share/elasticsearch/data
---
apiVersion: v1
kind: Service
metadata:
  name: es-entrypoint
spec:
  selector:
    name: es
  ports:
    - port: 9200
      targetPort: 9200
      protocol: TCP
  type: NodePort

0 个答案:

没有答案