本文主要是介绍kubernetes StatefulSet 部署 elasticsearch cluster,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用Kubernetes
StatefulSet
部署Elasticsearch
.
Service 配置
下面是一份elasticsearch
service
的配置。
apiVersion: v1
kind: Service
metadata:name: es-cluster-node
spec:clusterIP: Noneselector:app: es-clusterports:- name: transportport: 9300protocol: TCP---# cluster ip
apiVersion: v1
kind: Service
metadata:name: es-cluster-external
spec:selector:app: es-clusterports:- name: httpport: 80targetPort: 9200type: ClusterIP
- 上面的
service
es-cluster-node
把clusterIP
设置为None
,这种service
被称为headless service
。具体什么是headless service
请自行搜索一下。es-cluster-node
设置的端口是9300
,用于elasticsearch
node
之间通信,选举等,走的是tcp
协议。 - 下面的
service
es-cluster-external
是一个常用的service
类型,映射9200
到80
端口,这个service
用于外部访问elasticsearch
。 - 这
2
个service
的selector
都为app: es-cluster
,说明这2
个service
对应的pod
都是相同的。
Ingress 配置
apiVersion: extensions/v1beta1
kind: Ingress
metadata:name: es-cluster-external
spec:rules:- host: xxx.comhttp:paths:- backend:serviceName: es-cluster-externalservicePort: 80path: /
ingress
配置的service
为es-cluster-external
,elasticsearch
能够让外部访问。因为es-cluster-node
只需要内部node
之间通信,所以我们不需要将它暴露。
ConfigMap 配置
用来配置elasticsearch.yml
。
apiVersion: v1
kind: ConfigMap
metadata:name: es-config
data:elasticsearch.yml: |node.name: ${HOSTNAME}cluster.name: my-elastic-clusternetwork.host: "0.0.0.0"bootstrap.memory_lock: falsediscovery.zen.ping.unicast.hosts: esnode-0.es-cluster-node.xxx.svc.cluster.local,esnode-1.es-cluster-node.xxx.svc.cluster.local,esnode-2.es-cluster-node.xxx.svc.cluster.localdiscovery.zen.minimum_master_nodes: 1xpack.security.enabled: falsexpack.monitoring.enabled: false
我们要重点专注discovery.zen.ping.unicast.hosts
配置,这里配置的值为esnode-0.es-cluster-node.xxx.svc.cluster.local…
。
由于headless service
能够让pod
之间直接通信,而不需要走kube-proxy
。使用headless service
时,pod
的dns
规则如下 {stateful-set-name}-{0…N}.{service-name}.{namespace}.svc.cluster.local
。
这里配置的service-name
是headless service
name
。
StatefulSet 配置
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:name: esnodelabels:app: es-cluster
spec:serviceName: es-cluster-nodereplicas: 3updateStrategy:type: RollingUpdatetemplate:metadata:labels:app: es-clusterspec:securityContext:fsGroup: 1000initContainers:- name: init-sysctlimage: busyboximagePullPolicy: IfNotPresentsecurityContext:privileged: true# increase mmap limitscommand: ["sysctl", "-w", "vm.max_map_count=262144"]containers:- name: elasticsearchresources:requests:memory: 300Micpu: 0.01limits:memory: 1.5Gicpu: 1securityContext:privileged: truerunAsUser: 1000capabilities:add:- IPC_LOCK- SYS_RESOURCEimage: docker.elastic.co/elasticsearch/elasticsearch:6.5.0imagePullPolicy: IfNotPresentenv:- name: ES_JAVA_OPTSvalue: "-Xms800m -Xmx800m"readinessProbe:httpGet:scheme: HTTPpath: /_cluster/health?local=trueport: 9200initialDelaySeconds: 5ports:- containerPort: 9200name: es-http- containerPort: 9300name: es-transportvolumeMounts:- name: es-datamountPath: /usr/share/elasticsearch/data- name: elasticsearch-configmountPath: /usr/share/elasticsearch/config/elasticsearch.ymlsubPath: elasticsearch.ymlvolumes:- name: elasticsearch-configconfigMap:name: es-configitems:- key: elasticsearch.ymlpath: elasticsearch.ymlvolumeClaimTemplates:- metadata:name: es-dataspec:accessModes: [ "ReadWriteOnce" ]resources:requests:storage: 1GistorageClassName: rbd
上面配置一份elasticsearch statefulset
配置。
volumeClaimTemplates
配置了pvc
volumeMounts
配置了pvc
,指定挂在路径。配置了elasticsearch.yml
,这个配置内容我们在上面的configmap
里指定了。spec.serviceName
必须和headless service
metadata.name
一致。
最后通过ingress
配置的url
,访问xxx.com/_nodes
查看是否部署成功。
这篇关于kubernetes StatefulSet 部署 elasticsearch cluster的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!