- 规划
· 部署三个节点集群
· 采用Pod控制器部署ES应用
· ConfigMap配置应用
· 通过SVC发布应用
· PV、PVC集群资源持久化数据
- 准备
Docker镜像,基于elasticsearch:7.9.3打包增加SSL密钥库文件,密钥库可以自己通过ES自带工具生成,集群统一配置,这里为了方便直接打进镜像
From elasticsearch:7.9.3
COPY elastic-certificates.p12 /usr/share/elasticsearch/config/
- Yaml 文件
PV、PVC 资源, 共三组
elastic-storage.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: elastic-master-pv
spec:
storageClassName: elastic-master-pv
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.31.233
path: /nfs/elastic/data/master
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: elastic-data1-pv
spec:
storageClassName: elastic-data1-pv
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.31.233
path: /nfs/elastic/data/data1
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: elastic-data2-pv
spec:
storageClassName: elastic-data2-pv
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.31.233
path: /nfs/elastic/data/data2
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elastic-master-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: elastic-master-pv
resources:
requests:
storage: 20Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elastic-data1-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: elastic-data1-pv
resources:
requests:
storage: 20Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elastic-data2-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: elastic-data2-pv
resources:
requests:
storage: 20Gi
Pod 声明 master.yaml
apiVersion: v1
kind: Pod
metadata:
name: elastic-master
labels:
app: es-master
spec:
containers:
- name: es-master
image: elasticsearch:7.9.3
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: ES_JAVA_OPTS
value: "-Xms4g -Xmx4g"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: network.publish_host
value: "master-node.default"
volumeMounts:
- name: elastic-data
mountPath: /usr/share/elasticsearch/data
- name: elastic-config
subPath: elasticsearch.yml
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
volumes:
- name: elastic-data
persistentVolumeClaim:
claimName: elastic-master-pvc
- name: elastic-config
configMap:
name: elastic-config-map
---
apiVersion: v1
kind: Service
metadata:
name: master-node
spec:
selector:
app: es-master
ports:
- name: http-1
protocol: TCP
port: 9200
targetPort: 9200
- name: tcp-1
protocol: TCP
port: 9300
targetPort: 9300
data1.yaml
apiVersion: v1
kind: Pod
metadata:
name: elastic-data1
labels:
app: es-data1
spec:
containers:
- name: es-data1
image: elasticsearch:7.9.3
resources:
requests:
memory: 8Gi
limits:
memory: 16Gi
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: ES_JAVA_OPTS
value: "-Xms8g -Xmx8g"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: network.publish_host
value: "data1-node.default"
volumeMounts:
- name: elastic-data
mountPath: /usr/share/elasticsearch/data
- name: elastic-config
subPath: elasticsearch.yml
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
volumes:
- name: elastic-data
persistentVolumeClaim:
claimName: elastic-data1-pvc
- name: elastic-config
configMap:
name: elastic-config-map
---
apiVersion: v1
kind: Service
metadata:
name: data1-node
spec:
selector:
app: es-data1
ports:
- name: http-1
protocol: TCP
port: 9200
targetPort: 9200
- name: tcp-1
protocol: TCP
port: 9300
targetPort: 9300
data2.yaml
apiVersion: v1
kind: Pod
metadata:
name: elastic-data2
labels:
app: es-data2
spec:
containers:
- name: es-data1
image: elasticsearch:7.9.3
resources:
requests:
memory: 8Gi
limits:
memory: 16Gi
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: ES_JAVA_OPTS
value: "-Xms8g -Xmx8g"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: network.publish_host
value: "data2-node.default"
volumeMounts:
- name: elastic-data
mountPath: /usr/share/elasticsearch/data
- name: elastic-config
subPath: elasticsearch.yml
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
volumes:
- name: elastic-data
persistentVolumeClaim:
claimName: elastic-master-pvc
- name: elastic-config
configMap:
name: elastic-config-map
---
apiVersion: v1
kind: Service
metadata:
name: data2-node
spec:
selector:
app: es-data2
ports:
- name: http-1
protocol: TCP
port: 9200
targetPort: 9200
- name: tcp-1
protocol: TCP
port: 9300
targetPort: 9300
ConfigMap 配置文件 elastic-map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: elastic-config-map
data:
elasticsearch.yml: |-
cluster:
name: aaron-cluster
initial_master_nodes:
- elastic-master
node:
name: ${POD_NAME}
master: true
data: true
max_local_storage_nodes: 3
discovery:
seed_hosts:
- master-node.default
- data1-node.default
- data2-node.default
network:
host: 0.0.0.0
indices:
memory:
index_buffer_size: 20%
bootstrap:
system_call_filter: false
http:
cors:
enabled: true
allow-origin: "*"
xpack:
security:
enabled: true
transport:
ssl:
enabled: true
verification_mode: certificate
keystore:
path: /usr/share/elasticsearch/config/elastic-certificates.p12
truststore:
path: /usr/share/elasticsearch/config/elastic-certificates.p12
- 发布所以资源
所有yaml放到同一目录
kubectl apply -f .
进入容器初始化集群密码
kubectl exec -it elastic-master bash
bin/elasticsearch-setup-passwords interactive
curl -u elastic localhost:9200/_cat/nodes?v
|