Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions addons/elasticsearch/configs/elasticsearch-6.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $clusterName := .CLUSTER_NAME }}
{{- $defaultRoles := .ELASTICSEARCH_ROLES }}
{{- $namespace := .CLUSTER_NAMESPACE }}
{{- $zoneAwareEnabled := .ZONE_AWARE_ENABLED }}

{{- $mode := "multi-node" }}
{{- if index . "mode" }}
Expand All @@ -17,7 +18,14 @@ cluster:
routing:
allocation:
awareness:
{{- if eq $zoneAwareEnabled "true" }}
attributes: zone,k8s_node_name
force:
zone:
values: ${ALL_ZONES}
{{- else }}
attributes: k8s_node_name
{{- end }}
# In ES 6.x, discovery configuration is handled differently
discovery:
{{- if eq $mode "multi-node" }}
Expand Down Expand Up @@ -64,6 +72,9 @@ network:
node:
attr:
k8s_node_name: ${NODE_NAME}
{{- if eq $zoneAwareEnabled "true" }}
zone: ${CURRENT_ZONE}
{{- end }}
name: ${POD_NAME}
store:
allow_mmap: false
Expand Down
11 changes: 11 additions & 0 deletions addons/elasticsearch/configs/elasticsearch-7.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $clusterName := .CLUSTER_NAME }}
{{- $defaultRoles := .ELASTICSEARCH_ROLES }}
{{- $namespace := .CLUSTER_NAMESPACE }}
{{- $zoneAwareEnabled := .ZONE_AWARE_ENABLED }}

{{- $mode := "multi-node" }}
{{- if index . "mode" }}
Expand All @@ -17,7 +18,14 @@ cluster:
routing:
allocation:
awareness:
{{- if eq $zoneAwareEnabled "true" }}
attributes: zone,k8s_node_name
force:
zone:
values: ${ALL_ZONES}
{{- else }}
attributes: k8s_node_name
{{- end }}
# INITIAL_MASTER_NODES_BLOCK_START
{{- if eq $mode "multi-node" }}
initial_master_nodes:
Expand Down Expand Up @@ -67,6 +75,9 @@ network:
node:
attr:
k8s_node_name: ${NODE_NAME}
{{- if eq $zoneAwareEnabled "true" }}
zone: ${CURRENT_ZONE}
{{- end }}
name: ${POD_NAME}
store:
allow_mmap: false
Expand Down
11 changes: 11 additions & 0 deletions addons/elasticsearch/configs/elasticsearch-8.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $clusterName := .CLUSTER_NAME }}
{{- $defaultRoles := .ELASTICSEARCH_ROLES }}
{{- $namespace := .CLUSTER_NAMESPACE }}
{{- $zoneAwareEnabled := .ZONE_AWARE_ENABLED }}

{{- $mode := "multi-node" }}
{{- if index . "mode" }}
Expand All @@ -12,7 +13,14 @@ cluster:
routing:
allocation:
awareness:
{{- if eq $zoneAwareEnabled "true" }}
attributes: zone,k8s_node_name
force:
zone:
values: ${ALL_ZONES}
{{- else }}
attributes: k8s_node_name
{{- end }}
# INITIAL_MASTER_NODES_BLOCK_START
{{- if eq $mode "multi-node" }}
initial_master_nodes:
Expand Down Expand Up @@ -62,6 +70,9 @@ network:
node:
attr:
k8s_node_name: ${NODE_NAME}
{{- if eq $zoneAwareEnabled "true" }}
zone: ${CURRENT_ZONE}
{{- end }}
name: ${POD_NAME}
store:
allow_mmap: false
Expand Down
78 changes: 78 additions & 0 deletions addons/elasticsearch/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env sh
cp /etc/pki/tls/* /usr/share/elasticsearch/config/
# Parse zone from zone-aware-mapping file based on NODE_NAME
# Zone-aware-mapping file format: YAML format with zone name as key and comma-separated node names as value
# Empty node list is allowed for a zone
# Example:
# zone1: node1,node2
# zone2: node3,node4,node5
# zone3:
ZONE_AWARE_MAPPING_FILE="/mnt/zone-aware-mapping/mapping"
if [ "${ZONE_AWARE_ENABLED}" = "true" ]; then
if [ ! -f "${ZONE_AWARE_MAPPING_FILE}" ]; then
echo "Error: ZONE_AWARE_ENABLED is true but zone-aware-mapping file not found at ${ZONE_AWARE_MAPPING_FILE}"
exit 1
fi
if [ -z "${NODE_NAME}" ]; then
echo "Error: ZONE_AWARE_ENABLED is true but NODE_NAME is not set"
exit 1
fi
CURRENT_ZONE=""
ZONES=()
# Parse YAML format: each line is "zone_name: node1,node2,..."
while IFS= read -r LINE || [ -n "${LINE}" ]; do
# Skip empty lines and comments
LINE="${LINE%%#*}" # Remove comments
LINE=$(echo "${LINE}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') # Trim whitespace
if [ -z "${LINE}" ]; then
continue
fi
# Split by first colon to get zone name and node list
ZONE_NAME="${LINE%%:*}"
NODE_LIST="${LINE#*:}"
# Trim whitespace
ZONE_NAME=$(echo "${ZONE_NAME}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
NODE_LIST=$(echo "${NODE_LIST}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Skip if zone name is empty (node list can be empty)
if [ -z "${ZONE_NAME}" ]; then
continue
fi
# Add zone to ZONES array (even if node list is empty)
ZONES+=("${ZONE_NAME}")
# Check if current node is in this zone (only if not found yet and node list is not empty)
if [ -z "${CURRENT_ZONE}" ] && [ -n "${NODE_LIST}" ]; then
IFS=',' read -ra NODES <<< "${NODE_LIST}"
for NODE in "${NODES[@]}"; do
NODE_TRIMMED=$(echo "${NODE}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "${NODE_TRIMMED}" ] && [ "${NODE_TRIMMED}" = "${NODE_NAME}" ]; then
export CURRENT_ZONE="${ZONE_NAME}"
break
fi
done
fi
done < "${ZONE_AWARE_MAPPING_FILE}"
if [ -z "${CURRENT_ZONE}" ]; then
echo "Error: ZONE_AWARE_ENABLED is true but failed to find zone for node ${NODE_NAME} in zone-aware-mapping file"
exit 1
fi
echo "CURRENT_ZONE: ${CURRENT_ZONE}"
# Check if ZONES is empty
if [ ${#ZONES[@]} -eq 0 ]; then
echo "Error: ZONE_AWARE_ENABLED is true but failed to find zones in zone-aware-mapping file"
exit 1
fi
export ALL_ZONES=$(IFS=,; echo "${ZONES[*]}")
echo "ALL_ZONES: ${ALL_ZONES}"
fi

# remove initial master nodes block if cluster has been formed
if [ -f "${CLUSTER_FORMED_FILE}" ]; then
sed -i '/# INITIAL_MASTER_NODES_BLOCK_START/,/# INITIAL_MASTER_NODES_BLOCK_END/d' config/elasticsearch.yml
fi
if [ -f /bin/tini ]; then
/bin/tini -- /usr/local/bin/docker-entrypoint.sh
elif [ -f /tini ]; then
/tini -- /usr/local/bin/docker-entrypoint.sh
else
/usr/local/bin/docker-entrypoint.sh
fi
24 changes: 11 additions & 13 deletions addons/elasticsearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,7 @@ runtime:
- sh
- -c
- |
cp /etc/pki/tls/* /usr/share/elasticsearch/config/
# remove initial master nodes block if cluster has been formed
if [ -f "${CLUSTER_FORMED_FILE}" ]; then
sed -i '/# INITIAL_MASTER_NODES_BLOCK_START/,/# INITIAL_MASTER_NODES_BLOCK_END/d' config/elasticsearch.yml
fi
if [ -f /bin/tini ]; then
/bin/tini -- /usr/local/bin/docker-entrypoint.sh
elif [ -f /tini ]; then
/tini -- /usr/local/bin/docker-entrypoint.sh
else
/usr/local/bin/docker-entrypoint.sh
fi

{{- .Files.Get "scripts/entrypoint.sh" | nindent 10 }}
env:
- name: POD_IP
valueFrom:
Expand Down Expand Up @@ -495,6 +483,11 @@ runtime:
readOnly: true
- mountPath: /tmp
name: tmp-volume
{{- if .Values.zoneAware.enabled }}
- mountPath: /mnt/zone-aware-mapping
name: zone-aware-mapping
readOnly: true
{{- end }}
- name: exporter
command:
- /bin/elasticsearch_exporter
Expand Down Expand Up @@ -607,6 +600,11 @@ runtime:
name: local-plugins
- emptyDir: { }
name: plugins
{{- if .Values.zoneAware.enabled }}
- name: zone-aware-mapping
configMap:
name: {{ .Values.zoneAware.configMap }}
{{- end }}
{{- end }}

{{- define "kibana.common" }}
Expand Down
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-data-6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-data-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-data-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-master-6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-master-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
2 changes: 2 additions & 0 deletions addons/elasticsearch/templates/cmpd-es-master-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ spec:
valueFrom:
tlsVarRef:
enabled: Optional
- name: ZONE_AWARE_ENABLED
value: {{ .Values.zoneAware.enabled | quote }}
{{ include "elasticsearch.common" . | nindent 2 }}
18 changes: 18 additions & 0 deletions addons/elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ kibanaVersions:
- ["8.9.1", "8.9.1", "8.9.1", false]
- ["8.15.5", "8.15.5", "8.15.5", false]

# @param zoneAware enable zone awareness
# @param zoneAware.enabled enable zone awareness
# @param zoneAware.configMap config map name for zone awareness mapping
# The config map will be mounted as a volume at /mnt/zone-aware-mapping/mapping
# The config map should have the following format:
# apiVersion: v1
# kind: ConfigMap
# metadata:
# name: elasticsearch-zone-aware-mapping
# data:
# mapping: |
# zone1: node1,node2
# zone2: node3,node4,node5
# zone3:
zoneAware:
enabled: false
configMap: elasticsearch-zone-aware-mapping

exporter:
service:
port: 9114