k8s部署elasticseadrch的yml文件
时间: 2023-07-18 22:15:49 浏览: 172
以下是一个部署 Elasticsearch 到 Kubernetes 集群的 YAML 文件示例:
```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.6.2
env:
- name: cluster.name
value: my-cluster
- name: discovery.seed_hosts
value: "elasticsearch-0.elasticsearch,elasticsearch-1.elasticsearch,elasticsearch-2.elasticsearch"
- name: cluster.initial_master_nodes
value: "elasticsearch-0,elasticsearch-1,elasticsearch-2"
ports:
- containerPort: 9200
name: rest
- containerPort: 9300
name: inter-node
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
volumes:
- name: data
persistentVolumeClaim:
claimName: elasticsearch-data
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
spec:
ports:
- port: 9200
name: rest
- port: 9300
name: inter-node
clusterIP: None
selector:
app: elasticsearch
```
这个示例假设您已经创建了一个永久卷申明 (PVC) 名为 `elasticsearch-data`,用于 Elasticsearch 数据存储。在上面的 YAML 文件中,Elasticsearch 容器被定义为一个有状态集合 (StatefulSet),其中有 3 个副本。此外,还定义了一个名为 `elasticsearch` 的服务,用于将流量路由到 Elasticsearch 容器。
阅读全文