singlenode-es
数据存储采用 hostpath 方式
Pod 多节点反亲和性调度,单节点失效
Node 调度, 只运行在指定的节点上
[root@master test]# cat singlenode-es-statefulset.yaml
#外部web访问服务
apiVersion: v1
kind: Service
metadata:
labels:
app: elasticsearch
name: elasticsearch-node
spec:
type: NodePort
ports:
- name: http
port: 9200
targetPort: 9200
nodePort: 30920
- name: transport
port: 9300
targetPort: 9300
nodePort: 30930
selector:
app: elasticsearch
---
# 内部访问服务
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-headless
labels:
app: elasticsearch
spec:
type: ClusterIP
clusterIP: None
ports:
- name: http
port: 9200
targetPort: 9200
- name: transport
port: 9300
targetPort: 9300
selector:
app: elasticsearch
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
serviceName: elasticsearch-headless
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
# 节点打上中间件标签并污染:kubectl taint nodes <node-name> middleware=true:NoSchedule
#tolerations:
# - key: "middleware"
# operator: "Equal"
# value: "true"
# effect: "NoSchedule"
# 当多节点生效:不允许同一个pod调度到同一个节点
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- middleware
topologyKey: "kubernetes.io/hostname"
#securityContext:
# fsGroup: 1000
initContainers:
- name: init-singlenode-es
image: busybox
command: ['sh', '-c', 'chmod -R 777 /data/k8s/elasticsearch']
volumeMounts:
- name: elasticsearch-data
mountPath: /data/k8s/elasticsearch/data
containers:
- name: elasticsearch
image: elasticsearch:7.8.0
imagePullPolicy: IfNotPresent
resources:
limits:
memory: "2Gi"
cpu: "1"
env:
- name: TZ
value: America/Sao_Paulo # 巴西: America/Sao_Paulo; 上海:Asia/Shanghai
- name: cluster.name
value: elasticsearch
- name: discovery.type
value: single-node
- name: http.max_content_length
value: 1gb
ports:
- containerPort: 9200
name: http
- containerPort: 9300
name: transport
volumeMounts:
- name: elasticsearch-data
mountPath: /usr/share/elasticsearch/data
- name: elasticsearch-plugins
mountPath: /usr/share/elasticsearch/plugins
volumes:
- name: elasticsearch-data
hostPath:
path: /data/k8s/elasticsearch/data
- name: elasticsearch-plugins
hostPath:
path: /data/k8s/elasticsearch/plugins
Last updated