104 lines
2.6 KiB
YAML
104 lines
2.6 KiB
YAML
|
|
---
|
|||
|
|
# Headless Service(StatefulSet 必需,哪怕单节点,无头)
|
|||
|
|
apiVersion: v1
|
|||
|
|
kind: Service
|
|||
|
|
metadata:
|
|||
|
|
name: elasticsearch
|
|||
|
|
namespace: es-test
|
|||
|
|
spec:
|
|||
|
|
clusterIP: None
|
|||
|
|
selector:
|
|||
|
|
app: elasticsearch
|
|||
|
|
ports:
|
|||
|
|
- port: 9200
|
|||
|
|
name: http
|
|||
|
|
- port: 9300
|
|||
|
|
name: transport
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
# 单节点 StatefulSet (有状态工作负载)
|
|||
|
|
apiVersion: apps/v1
|
|||
|
|
kind: StatefulSet
|
|||
|
|
metadata:
|
|||
|
|
name: elasticsearch
|
|||
|
|
namespace: es-test
|
|||
|
|
spec:
|
|||
|
|
serviceName: "elasticsearch"
|
|||
|
|
replicas: 1 # 👈 单节点!
|
|||
|
|
selector:
|
|||
|
|
matchLabels:
|
|||
|
|
app: elasticsearch
|
|||
|
|
template:
|
|||
|
|
metadata:
|
|||
|
|
labels:
|
|||
|
|
app: elasticsearch
|
|||
|
|
spec:
|
|||
|
|
# ✅ 关键:initContainer 修复内核参数(腾讯云默认可能不足)
|
|||
|
|
initContainers:
|
|||
|
|
- name: increase-vm-max-map
|
|||
|
|
image: busybox
|
|||
|
|
command: ["sysctl", "-w", "vm.max_map_count=262144"]
|
|||
|
|
securityContext:
|
|||
|
|
privileged: true
|
|||
|
|
|
|||
|
|
containers:
|
|||
|
|
- name: elasticsearch
|
|||
|
|
image: docker.elastic.co/elasticsearch/elasticsearch:9.2.2
|
|||
|
|
env:
|
|||
|
|
- name: discovery.type
|
|||
|
|
value: "single-node" # ⚠️ 必须!否则 ES 9 会报错退出
|
|||
|
|
- name: cluster.name
|
|||
|
|
value: "test-es-cluster"
|
|||
|
|
- name: node.name
|
|||
|
|
value: "es-test-node"
|
|||
|
|
- name: ES_JAVA_OPTS
|
|||
|
|
value: "-Xms1g -Xmx1g" # 测试环境 1G 足够
|
|||
|
|
ports:
|
|||
|
|
- containerPort: 9200
|
|||
|
|
name: http
|
|||
|
|
- containerPort: 9300
|
|||
|
|
name: transport
|
|||
|
|
volumeMounts:
|
|||
|
|
- name: data
|
|||
|
|
mountPath: /usr/share/elasticsearch/data
|
|||
|
|
|
|||
|
|
# 探针(可选,加快感知)
|
|||
|
|
readinessProbe:
|
|||
|
|
httpGet:
|
|||
|
|
path: /_cluster/health
|
|||
|
|
port: 9200
|
|||
|
|
initialDelaySeconds: 20
|
|||
|
|
periodSeconds: 10
|
|||
|
|
livenessProbe:
|
|||
|
|
httpGet:
|
|||
|
|
path: /_cluster/health
|
|||
|
|
port: 9200
|
|||
|
|
initialDelaySeconds: 60
|
|||
|
|
periodSeconds: 30
|
|||
|
|
|
|||
|
|
# ✅ ES 9 默认非 root 运行,必须设置
|
|||
|
|
securityContext:
|
|||
|
|
runAsUser: 1000
|
|||
|
|
runAsGroup: 1000
|
|||
|
|
fsGroup: 1000
|
|||
|
|
|
|||
|
|
# 腾讯云 CBS 需要 RWO,单节点没问题
|
|||
|
|
volumes:
|
|||
|
|
- name: data
|
|||
|
|
persistentVolumeClaim:
|
|||
|
|
claimName: es-data-pvc
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
# 单独创建 PVC(StatefulSet 用 volumeClaimTemplates 更规范,但单节点直接 PVC 更直观)
|
|||
|
|
apiVersion: v1
|
|||
|
|
kind: PersistentVolumeClaim
|
|||
|
|
metadata:
|
|||
|
|
name: es-data-pvc
|
|||
|
|
namespace: es-test
|
|||
|
|
spec:
|
|||
|
|
accessModes:
|
|||
|
|
- ReadWriteOnce
|
|||
|
|
storageClassName: cbs # 👈 腾讯云默认存储类(如用高性能 SSD 改为 cbs-premium)
|
|||
|
|
resources:
|
|||
|
|
requests:
|
|||
|
|
storage: 20Gi # 测试够用,可调小如 10Gi
|