以下是一个简化的Elasticsearch 8.12.0在Kubernetes上的部署实例,包括配置和部署文件:
- 创建Elasticsearch持久卷声明 (PVC) -
elasticsearch-pvc.yaml
:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elasticsearch-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
- 创建Elasticsearch部署 (Deployment) -
elasticsearch-deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
spec:
replicas: 3
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
resources:
limits:
memory: 2Gi
cpu: 1
requests:
memory: 2Gi
cpu: 1
env:
- name: discovery.type
value: k8s
- name: ELASTIC_PASSWORD
value: "yourpassword"
- name: replicaShards
value: "1"
ports:
- name: http
containerPort: 9200
- name: inter-node
containerPort: 9300
volumeMounts:
- name: elasticsearch-pvc
mountPath: /usr/share/elasticsearch/data
volumes:
- name: elasticsearch-pvc
persistentVolumeClaim:
claimName: elasticsearch-pvc
- 创建Elasticsearch服务 (Service) -
elasticsearch-service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
spec:
selector:
app: elasticsearch
ports:
- name: http
port: 9200
targetPort: http
- name: inter-node
port: 9300
targetPort: inter-node
部署到Kubernetes集群时,首先创建PVC,然后创建Deployment和Service。确保你的Kubernetes集群已经准备好,并且kubectl
命令行工具已经配置好能够访问该集群。
部署步骤示例:
kubectl apply -f elasticsearch-pvc.yaml
kubectl apply -f elasticsearch-deployment.yaml
kubectl apply -f elasticsearch-service.yaml
这样就会在Kubernetes上部署一个具有3个副本的Elasticsearch集群。记得替换yourpassword
为你自己的密码,并根据需要调整资源限制和副本数量。