-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(apps) add elasticsearch application
Add an independant elasticsearch app with a configurable high availability cluster. It is designed to run without persistent volume and it supports rolling updates without any data loss. On the other hand, a full restart of the ES cluster (without rolling update) results in data loss and requires to recreate indexes.
- Loading branch information
Showing
18 changed files
with
470 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/elasticsearch/templates/services/app/configs/elasticsearch.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cluster.name: {{ elasticsearch_cluster_name }} | ||
|
||
# Bind address (listen to all interfaces) | ||
network.host: "0.0.0.0" | ||
|
||
{% if elasticsearch_image_tag is version('6.0', '<') %} | ||
bootstrap.mlockall: {{elasticsearch_memory_lock}} | ||
{% else %} | ||
bootstrap.memory_lock: {{elasticsearch_memory_lock}} | ||
{% endif %} | ||
|
||
# Cluster discovery address, to get the peer list. | ||
# This is a kubernetes service that target every ES running nodes, even if they | ||
# are not ready yet. | ||
discovery.zen.ping.unicast.hosts: elasticsearch-discovery.{{ project_name }}.svc | ||
|
||
discovery.zen.minimum_master_nodes: {{ elasticsearch_minimum_master_nodes }} | ||
|
||
# Security features are disabled by default on ES basic and trial licenses | ||
xpack.security.enabled: false | ||
|
||
# Monitoring is not supported in this arnold application yet | ||
xpack.monitoring.enabled: false |
57 changes: 57 additions & 0 deletions
57
apps/elasticsearch/templates/services/app/configs/readiness-probe.sh.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
declare -r ES_HOST="127.0.0.1" | ||
declare -i ES_PORT={{ elasticsearch_api_port }} | ||
declare -r ES_STARTED="/tmp/es_started" | ||
|
||
function testStatus() { | ||
status_to_test="${1}" | ||
expected_status="${2}" | ||
|
||
declare -A statuses=( ["red"]=1 ["yellow"]=2 ["green"]=3 ) | ||
|
||
if [[ -z "${status_to_test}" || -z "${statuses[${status_to_test}]}" ]] ; then | ||
echo "Error: unknown status_to_test [${status_to_test}]" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "${expected_status}" || -z "${statuses[${expected_status}]}" ]]; then | ||
echo "Error: unknown expected_status [${expected_status}]" 1>&2 | ||
exit 2 | ||
fi | ||
|
||
if [ "${statuses[$status_to_test]}" -lt "${statuses[${expected_status}]}" ]; then | ||
echo "Assertion failed: ${status_to_test} < ${expected_status}" | ||
exit 3 | ||
fi | ||
} | ||
|
||
if [ -f "${ES_STARTED}" ]; then | ||
echo -n "Elasticsearch is already running. Checking if API is alive..." | ||
curl -fsSL "http://${ES_HOST}:${ES_PORT}/" > /dev/null | ||
echo "OK" | ||
else | ||
echo "Waiting for elasticsearch cluster to be running and in green state..." | ||
health_status=$( | ||
curl -fsSL "http://${ES_HOST}:${ES_PORT}/_cat/health?h=status" | \ | ||
sed -r 's/^[[:space:]]+|[[:space:]]+$//g' | ||
) | ||
testStatus "${health_status}" "green" | ||
|
||
echo "Waiting for initializing_shards to be 0" | ||
init_shards=$( | ||
curl -fsSL "http://${ES_HOST}:${ES_PORT}/_cat/health?h=init" | \ | ||
sed -r 's/^[[:space:]]+|[[:space:]]+$//g' | ||
) | ||
|
||
if [ "${init_shards}" -gt 0 ]; then | ||
echo "Synchronization not ready yet, initializing_shards = ${init_shards}" | ||
exit 4 | ||
fi | ||
|
||
touch "${ES_STARTED}" | ||
|
||
echo "Elasticsearch cluster is up (status = ${health_status})" | ||
fi |
33 changes: 33 additions & 0 deletions
33
apps/elasticsearch/templates/services/app/configs/set-index-template.sh.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
declare -i MAX_RETRY=20 | ||
declare -i RETRY_DELAY=5 | ||
declare -i retry=0 | ||
|
||
echo -n "Waiting for ES service to be up." | ||
while ! curl --output /dev/null --silent --max-time 1 --connect-timeout 1 --head --fail "http://elasticsearch.{{project_name}}.svc:{{ elasticsearch_api_port }}/" | ||
do | ||
echo -n "." | ||
((retry++)) && ((retry==MAX_RETRY)) && echo "ERROR: timeout" && exit 62 | ||
sleep $RETRY_DELAY | ||
done | ||
|
||
curl -fssL \ | ||
-X PUT "http://elasticsearch.{{ project_name }}.svc:{{ elasticsearch_api_port }}/_template/default" \ | ||
-H 'Content-Type: application/json' \ | ||
-d \ | ||
'{ | ||
{% if elasticsearch_image_tag is version('6.0', '<') %} | ||
"template" : "*", | ||
{% else %} | ||
"index_patterns": ["*"], | ||
{% endif %} | ||
"settings" : { | ||
"number_of_shards": {{ elasticsearch_index_default_shards }}, | ||
"number_of_replicas": {{ elasticsearch_index_default_replicas }}, | ||
"index.store.type": "{{ elasticsearch_index_store_type }}", | ||
"index.unassigned.node_left.delayed_timeout": "{{ elasticsearch_index_node_left_delayed_timeout }}" | ||
} | ||
}' |
Oops, something went wrong.