帮我写一个在k8s搭建es集群的yaml文件
时间: 2024-01-22 16:17:38 浏览: 87
当然可以,以下是一个简单的在Kubernetes中部署Elasticsearch集群的yaml文件:
```
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elasticsearch
spec:
serviceName: elasticsearch
replicas: 3
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
env:
- name: discovery.type
value: "single-node"
resources:
limits:
memory: 2Gi
requests:
cpu: 100m
memory: 2Gi
ports:
- containerPort: 9200
name: rest
protocol: TCP
- containerPort: 9300
name: inter-node
protocol: TCP
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
volumes:
- name: data
persistentVolumeClaim:
claimName: elasticsearch-data
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
spec:
selector:
app: elasticsearch
ports:
- name: rest
port: 9200
targetPort: rest
protocol: TCP
- name: inter-node
port: 9300
targetPort: inter-node
protocol: TCP
clusterIP: None
```
该yaml文件包括了一个3个副本的StatefulSet,以及一个Service来暴露Elasticsearch集群。此处使用的是单节点发现模式,因此每个Elaticsearch节点都是一个独立的节点。此外,还定义了一个名为“elasticsearch-data”的持久卷声明,用于存储Elasticsearch的数据。
请注意,这只是一个基本示例,你可能需要根据自己的需求进行修改。
阅读全文