elasticsearch|kubernetes搭建es集群

【elasticsearch|kubernetes搭建es集群】问题描述:(es环境为7.2.0)
新版废弃了原先discovery.zen.ping.unicast.hosts及discovery.zen.minimum_master_nodes的探测方式,而是改为了discovery.seed_hosts及cluster.initial_master_nodes,其中第一项换汤不换药,值还是一样的,我们还是填内部服务域名,而后一项就有点恶心了,这项在实体服务器上配置没任何问题,把符合master节点的ip或主机名配进去就可以了,但在k8s环境下,master节点的ip是pod ip,随即分配的,主机名由于是deployment下部署的,主机名的尾巴也是随机字符,同样无法指定,不配的话各节点服务器无法选举master,无法组成集群。
办法:将es-master部署方式由depolyment调整至statefulset,这样就解决了主机名无法指定的问题,配置如下:

- name: cluster.initial_master_nodes value: "elasticsearch-master-0,elasticsearch-master-1,elasticsearch-master-2"

下面是配置文件,全放一起了
--- kind: StatefulSet metadata: labels: app: elasticsearch role: master name: elasticsearch-master namespace: elastic spec: replicas: 2 serviceName: elasticsearch-master selector: matchLabels: app: elasticsearch role: master template: metadata: labels: app: elasticsearch role: master spec: serviceAccountName: elasticsearch-admin restartPolicy: Always securityContext: fsGroup: 1000 containers: - name: elasticsearch-master image: elasticsearch:7.2.0 imagePullPolicy: IfNotPresent securityContext: privileged: true ports: - containerPort: 9200 protocol: TCP - containerPort: 9200 protocol: TCP env: - name: cluster.name value: "es_cluster" - name: node.master value: "true" - name: node.data value: "false" - name: discovery.seed_hosts value: "elasticsearch-discovery" - name: cluster.initial_master_nodes value: "elasticsearch-master-0,elasticsearch-master-1" - name: node.ingest value: "false" - name: ES_JAVA_OPTS value: "-Xms1g -Xmx1g" --- kind: Service apiVersion: v1 metadata: labels: app: elasticsearch name: elasticsearch-discovery namespace: elastic spec: ports: - port: 9300 targetPort: 9300 selector: app: elasticsearch role: master --- apiVersion: v1 kind: Service metadata: name: elasticsearch-data-service namespace: elastic labels: app: elasticsearch role: data spec: ports: - port: 9200 name: outer - port: 9300 name: inner clusterIP: None selector: app: elasticsearch role: data ---kind: StatefulSet metadata: labels: app: elasticsearch role: master name: elasticsearch-data namespace: elastic spec: replicas: 2 serviceName: elasticsearch-data selector: matchLabels: app: elasticsearch role: data template: metadata: labels: app: elasticsearch role: data spec: serviceAccountName: elasticsearch-admin restartPolicy: Always securityContext: fsGroup: 1000 containers: - name: elasticsearch-data image: elasticsearch:7.2.0 imagePullPolicy: IfNotPresent securityContext: privileged: true ports: - containerPort: 9200 protocol: TCP - containerPort: 9300 protocol: TCP env: - name: cluster.name value: "es_cluster" - name: node.master value: "fasle" - name: node.data value: "true" - name: discovery.seed_hosts # value: "elasticsearch-discovery" - name: cluster.initial_master_nodes value: "elasticsearch-master-0,elasticsearch-master-1" - name: node.ingest value: "false" - name: ES_JAVA_OPTS value: "-Xms1g -Xmx1g"

可以建议大家用rancher进行部署,当然前提得知道es集群搭建的原理,我用rancher搭建的时候就不太熟悉rancher的操作,走了很多弯路。(es的环境变量可以用configmap进行代替,两者都可以使用的)

    推荐阅读