根据official es docs,禁用交换是Elasticsearch可获得的最佳性能提升之一。
但是,事实证明配置起来很困难。我花了很多时间研究并尝试使用不同的方法来使用Kubernetes上的官方ES docker镜像禁用交换。
将bootstrap.memory_lock: true
设置为环境变量时,映像无法启动,并显示错误:Unable to lock JVM Memory: error=12, reason=Cannot allocate memory. This can result in part of the JVM being swapped out. Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536
。正如文档所指出的那样,这是意料之中的。我什至用设置挂载了自定义/etc/security/limits.conf
,但这失败了。
在k8s上使用官方es映像时,建议禁用交换的方法是什么?
而且,这是我的Yaml的相关部分
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: elastic-data
spec:
serviceName: elastic-data
replicas: 1
template:
spec:
securityContext:
runAsUser: 0
fsGroup: 0
containers:
- name: elastic-data
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.0
env:
- name: ES_JAVA_OPTS
value: "-Xms2g -Xmx2g"
- name: cluster.name
value: "elastic-devs"
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.zen.ping.unicast.hosts
value: "elastic-master.default.svc.cluster.local"
- name: node.master
value: "false"
- name: node.ingest
value: "false"
- name: node.data
value: "true"
- name: network.host
value: "0.0.0.0"
- name: path.data
value: /usr/share/elasticsearch/data
- name: indices.memory.index_buffer_size
value: "512MB"
- name: bootstrap.memory_lock
value: "true"
resources:
requests:
memory: "3Gi"
limits:
memory: "3Gi"
ports:
- containerPort: 9300
name: transport
- containerPort: 9200
name: http
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: swappiness-config
mountPath: /etc/security/limits.conf
subPath: limits.conf
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: pvc-es
- name: swappiness-config
configMap:
name: swappiness-config
items:
- key: limits.conf
path: limits.conf
limits.conf
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
elasticsearch hard nofile 65536
elasticsearch soft nofile 65536
答案 0 :(得分:1)
我认为,我的Yaml中的ulimit未被识别,所以我遵循this post并创建了一个带有用于设置设置的自定义入口点的图像。
答案 1 :(得分:0)
您使用的是哪种图像类型? 如果其容器优化的操作系统(cos)尝试切换到基于Ubuntu的映像