Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/elasticsearch] support elasticsearch 7 & graceful termination on master nodes #13290

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion stable/elasticsearch/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: elasticsearch
home: https://www.elastic.co/products/elasticsearch
version: 1.26.1
version: 1.27.0
appVersion: 6.7.0
description: Flexible and powerful open source, distributed real-time search and analytics
engine.
Expand Down
71 changes: 28 additions & 43 deletions stable/elasticsearch/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ $majorAppVersion := regexFind "[0-9]*" .Values.appVersion | int -}}
{{ $minorAppVersion := regexFind "[0-9]*.[0-9]*" .Values.appVersion | float64 -}}
apiVersion: v1
kind: ConfigMap
Expand All @@ -14,68 +15,51 @@ data:

node.data: ${NODE_DATA:true}
node.master: ${NODE_MASTER:true}
{{- if hasPrefix "5." .Values.appVersion }}
node.ingest: ${NODE_INGEST:true}
{{- else if hasPrefix "6." .Values.appVersion }}
{{- if not (lt $majorAppVersion 5) }}
node.ingest: ${NODE_INGEST:true}
{{- end }}
node.name: ${HOSTNAME}

network.host: 0.0.0.0

{{- if hasPrefix "2." .Values.appVersion }}
# see https://github.com/kubernetes/kubernetes/issues/3595
bootstrap.mlockall: ${BOOTSTRAP_MLOCKALL:false}

discovery:
zen:
ping.unicast.hosts: ${DISCOVERY_SERVICE:}
minimum_master_nodes: ${MINIMUM_MASTER_NODES:2}
{{- else if hasPrefix "5." .Values.appVersion }}
# see https://github.com/kubernetes/kubernetes/issues/3595
bootstrap.memory_lock: ${BOOTSTRAP_MEMORY_LOCK:false}

discovery:
zen:
ping.unicast.hosts: ${DISCOVERY_SERVICE:}
minimum_master_nodes: ${MINIMUM_MASTER_NODES:2}

{{- if .Values.cluster.xpackEnable }}
{{- if and (not (lt $majorAppVersion 5)) .Values.cluster.xpackEnable }}
# see https://www.elastic.co/guide/en/x-pack/current/xpack-settings.html
{{- if or ( gt $minorAppVersion 5.4 ) ( eq $minorAppVersion 5.4 ) }}
# or https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack.html
{{- if not ( lt $minorAppVersion 5.4 ) }}
xpack.ml.enabled: ${XPACK_ML_ENABLED:false}
{{- end }}
{{- end }}

xpack.monitoring.enabled: ${XPACK_MONITORING_ENABLED:false}
{{- if gt $minorAppVersion 6.3 }}
xpack.monitoring.collection.enabled: ${XPACK_MONITORING_ENABLED:false}
{{- end }}

xpack.security.enabled: ${XPACK_SECURITY_ENABLED:false}
xpack.watcher.enabled: ${XPACK_WATCHER_ENABLED:false}
{{- else }}
{{- if or ( gt $minorAppVersion 5.4 ) ( eq $minorAppVersion 5.4 ) }}
xpack.ml.enabled: false
{{- end }}
xpack.monitoring.enabled: false
xpack.security.enabled: false
xpack.watcher.enabled: false
{{- end }}
{{- else if hasPrefix "6." .Values.appVersion }}


{{- if not (lt $majorAppVersion 5) }}
# see https://github.com/kubernetes/kubernetes/issues/3595
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this specific to ES7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I have no idea about this issue and es7, but es nodes fail with bootstrap.memory_lock: true option.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check this and find the source before blindly merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that 6.7 doc and 7.0 doc are same and nothing has changed about this issue.

and reference in elastic's own chart elastic/helm-charts#7

bootstrap.memory_lock: ${BOOTSTRAP_MEMORY_LOCK:false}
{{- else if not (lt $majorAppVersion 2) }}
# see https://github.com/kubernetes/kubernetes/issues/3595
bootstrap.mlockall: ${BOOTSTRAP_MLOCKALL:false}
{{- end }}

{{- if not (lt $majorAppVersion 7) }}
discovery.seed_hosts:
- ${DISCOVERY_SERVICE:}
cluster.initial_master_nodes:
{{- $replicas := .Values.master.replicas | int }}
{{- range $i := untilStep 0 $replicas 1 }}
- {{ template "elasticsearch.master.fullname" $ }}-{{ $i }}
{{- end }}
{{- else if not (lt $majorAppVersion 2) }}
discovery:
zen:
ping.unicast.hosts: ${DISCOVERY_SERVICE:}
minimum_master_nodes: ${MINIMUM_MASTER_NODES:2}

{{- if and ( .Values.cluster.xpackEnable ) ( gt $minorAppVersion 6.3 ) }}
# see https://www.elastic.co/guide/en/x-pack/current/xpack-settings.html
# After 6.3 xpack systems changed and are enabled by default and different configs manage them this enables monitoring
xpack.monitoring.collection.enabled: ${XPACK_MONITORING_ENABLED:false}
{{- else if .Values.cluster.xpackEnable }}
# see https://www.elastic.co/guide/en/x-pack/current/xpack-settings.html
xpack.ml.enabled: ${XPACK_ML_ENABLED:false}
xpack.monitoring.enabled: ${XPACK_MONITORING_ENABLED:false}
xpack.security.enabled: ${XPACK_SECURITY_ENABLED:false}
xpack.watcher.enabled: ${XPACK_WATCHER_ENABLED:false}
{{- end }}
{{- end }}

# see https://github.com/elastic/elasticsearch-definitive-guide/pull/679
Expand All @@ -90,6 +74,7 @@ data:
{{- with .Values.cluster.config }}
{{ toYaml . | indent 4 }}
{{- end }}

{{- if hasPrefix "2." .Values.appVersion }}
logging.yml: |-
# you can override this using by setting a system property, for example -Des.logger.level=DEBUG
Expand Down
45 changes: 45 additions & 0 deletions stable/elasticsearch/templates/master-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,51 @@ spec:
subPath: elasticsearch.keystore
readOnly: true
{{- end }}
# This sidecar will fix slow master re-election.
# https://github.com/helm/charts/issues/8785
- name: elasticsearch-master-graceful-termination-handler
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
command:
- "sh"
- -c
- |
#!/usr/bin/env bash
set -eo pipefail

http () {
local path="${1}"
if [ -n "${ELASTIC_USERNAME}" ] && [ -n "${ELASTIC_PASSWORD}" ]; then
BASIC_AUTH="-u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD}"
else
BASIC_AUTH=''
fi
curl -XGET -s -k --fail ${BASIC_AUTH} http://{{ template "elasticsearch.client.fullname" . }}:9200${path}
}

cleanup () {
while true ; do
local master="$(http "/_cat/master?h=node")"
if [[ $master == "{{ template "elasticsearch.master.fullname" . }}"* && $master != "${HOSTNAME}" ]]; then
echo "This node is not master."
break
fi
echo "This node is still master, waiting gracefully for it to step down"
sleep 1
done

exit 0
}

trap cleanup SIGTERM

sleep infinity &
wait $!
{{- range $key, $value := .Values.cluster.env }}
env:
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range $pullSecret := .Values.image.pullSecrets }}
Expand Down