diff --git a/examples/elastic/helm/templates/_helpers.tpl b/examples/elastic/helm/templates/_helpers.tpl new file mode 100644 index 0000000..594e4dd --- /dev/null +++ b/examples/elastic/helm/templates/_helpers.tpl @@ -0,0 +1,3 @@ +{{- define "elasticsearch.masterNodes" -}} +es-master-0.es-master,es-master-1.es-master,es-master-2.es-master +{{- end -}} diff --git a/examples/elastic/helm/templates/identity.yaml b/examples/elastic/helm/templates/identity.yaml index 8b1c601..30d934c 100644 --- a/examples/elastic/helm/templates/identity.yaml +++ b/examples/elastic/helm/templates/identity.yaml @@ -1,2 +1,2 @@ kind: identity -name: {{ .Values.elasticsearch.identity.name }} +name: {{ .Values.elasticsearch.identity.name }}{{ .Values.elasticsearch.nameSuffix }} diff --git a/examples/elastic/helm/templates/policy.yaml b/examples/elastic/helm/templates/policy.yaml index a78a0ce..17729fe 100644 --- a/examples/elastic/helm/templates/policy.yaml +++ b/examples/elastic/helm/templates/policy.yaml @@ -1,5 +1,5 @@ kind: policy -name: elasticsearch-policy-{{ .Values.cpln.gvc }} +name: elasticsearch-policy-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }} origin: default bindings: - permissions: @@ -8,5 +8,5 @@ bindings: - //gvc/{{ .Values.cpln.gvc }}/identity/{{ .Values.elasticsearch.identity.name }} targetKind: secret targetLinks: - - //secret/elasticsearch-config-{{ .Values.cpln.gvc }} - - //secret/elasticsearch-init-{{ .Values.cpln.gvc }} + - //secret/elasticsearch-config-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }} + - //secret/elasticsearch-init-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }} diff --git a/examples/elastic/helm/templates/secret.yaml b/examples/elastic/helm/templates/secret.yaml index b44409f..7b8c129 100644 --- a/examples/elastic/helm/templates/secret.yaml +++ b/examples/elastic/helm/templates/secret.yaml @@ -1,5 +1,5 @@ kind: secret -name: elasticsearch-config-{{ .Values.cpln.gvc }} +name: elasticsearch-config-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }} type: opaque data: encoding: plain @@ -10,20 +10,49 @@ data: xpack.security.enabled: {{ .Values.elasticsearch.config.security.enabled }} node.name: node-name-placeholder + # Recovery and allocation settings + cluster.routing.allocation.node_concurrent_incoming_recoveries: {{ .Values.elasticsearch.config.recovery.incomingRecoveries }} + cluster.routing.allocation.node_concurrent_outgoing_recoveries: {{ .Values.elasticsearch.config.recovery.outgoingRecoveries }} + indices.recovery.max_bytes_per_sec: {{ .Values.elasticsearch.config.recovery.maxBytesPerSec }} + + # Bulk operation settings + http.max_content_length: 100mb + http.max_initial_line_length: 4kb + http.max_header_size: 8kb + http.compression: true + http.cors.enabled: true + http.cors.allow-origin: "*" + http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE + http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization + # Node roles based on environment variable node.roles: ${NODE_ROLES} # Discovery configuration discovery.seed_hosts: - {{- if .Values.elasticsearch.nodes.master.enabled }} - {{- range $i := until (.Values.elasticsearch.nodes.master.replicas | int) }} - - es-master-{{ $i }}.es-master + {{- range $nodeType, $config := .Values.elasticsearch.nodes }} + {{- if $config.enabled }} + - es-{{ $nodeType }}.{{ $.Values.cpln.gvc }}.cpln.local + {{- end }} + {{- end }} + + # Network settings + network.publish_host: ${POD_NAME}.{{ .Values.cpln.gvc }}.cpln.local + network.bind_host: 0.0.0.0 + + # Cluster settings + cluster.initial_master_nodes: + {{- range $nodeType, $config := .Values.elasticsearch.nodes }} + {{- if $config.enabled }} + {{- range $i, $e := until (int $config.replicas) }} + - es-{{ $nodeType }}-{{ $i }}.{{ $.Values.cpln.gvc }}.cpln.local + {{- end }} {{- end }} {{- end }} --- kind: secret -name: elasticsearch-init-{{ .Values.cpln.gvc }} +name: elasticsearch-init-{{ .Values.cpln.gvc }}{{ .Values.elasticsearch.nameSuffix }} type: opaque data: encoding: plain @@ -35,75 +64,25 @@ data: set -o pipefail set -x - error(){ - local message="${1:?missing message}" - echo "ERROR: ${message}" - exit 1 - } + # Debug: Print environment variables + echo "Environment variables:" + env | sort - cp /usr/share/elasticsearch/config-custom/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml + # Set node name + NODE_NAME="${POD_NAME}.{{ .Values.cpln.gvc }}.cpln.local" + echo "Setting node name to: $NODE_NAME" + # Copy and configure elasticsearch.yml + cp /usr/share/elasticsearch/config-custom/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml ELASTIC_CONFIG_FILE=/usr/share/elasticsearch/config/elasticsearch.yml - replace_placeholder() { - local placeholder="${1:?missing placeholder value}" - local value="${2:?missing value}" - sed -i "s/$placeholder/$value/g" "$ELASTIC_CONFIG_FILE" - } - - POD_ID=$(echo "$POD_NAME" | rev | cut -d'-' -f 1 | rev) - WORKLOAD_NAME=$(echo $CPLN_WORKLOAD | sed 's|.*/workload/\([^/]*\)$|\1|') - - replace_placeholder "node-name-placeholder" "${POD_NAME}.${WORKLOAD_NAME}" - - echo "Starting Elasticsearch process in the background..." - /usr/local/bin/docker-entrypoint.sh & - - ELASTIC_PID=$! - - echo "Waiting for Elasticsearch service to be available..." - while ! curl -s http://localhost:9200 > /dev/null; do - echo "Elasticsearch is not yet available. Retrying in 5 seconds..." - sleep 5 - done - - # Check if this is a master node - if [[ "$NODE_ROLES" == *"master"* ]]; then - CLUSTER_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:9200/_cluster/health || echo "000") - - if [[ "$CLUSTER_STATUS" -ne 200 ]]; then - echo "Cluster is not initialized. Adding cluster.initial_master_nodes to configuration." - - # Add cluster.initial_master_nodes only if not already present - if ! grep -q "cluster.initial_master_nodes" "$ELASTIC_CONFIG_FILE"; then - echo "Adding cluster.initial_master_nodes..." - cat <> "$ELASTIC_CONFIG_FILE" - - cluster.initial_master_nodes: - {{- if .Values.elasticsearch.nodes.master.enabled }} - {{- range $i := until (.Values.elasticsearch.nodes.master.replicas | int) }} - - es-master-{{ $i }}.es-master - {{- end }} - {{- end }} - EOF - else - echo "cluster.initial_master_nodes already present in configuration. Skipping." - fi - else - echo "Cluster is already initialized. Skipping cluster.initial_master_nodes configuration." - fi - else - echo "This node is not a master node. Skipping cluster.initial_master_nodes configuration." - fi - - # Stop the initial Elasticsearch process - echo "Stopping the initial Elasticsearch process..." - kill $ELASTIC_PID - wait $ELASTIC_PID 2>/dev/null || true + # Replace node name placeholder + sed -i "s/node-name-placeholder/$NODE_NAME/g" "$ELASTIC_CONFIG_FILE" - echo "Printing elasticsearch.yml" + # Print configuration for debugging + echo "Elasticsearch configuration:" cat $ELASTIC_CONFIG_FILE - # Restart Elasticsearch process to apply configuration changes - echo "Restarting Elasticsearch process..." + # Start Elasticsearch + echo "Starting Elasticsearch process..." exec /usr/local/bin/docker-entrypoint.sh diff --git a/examples/elastic/helm/templates/volumeset.yaml b/examples/elastic/helm/templates/volumeset.yaml index 45c5fc1..fee54ac 100644 --- a/examples/elastic/helm/templates/volumeset.yaml +++ b/examples/elastic/helm/templates/volumeset.yaml @@ -2,11 +2,11 @@ {{- if $config.enabled }} --- kind: volumeset -name: es-{{ $nodeType }}-data +name: es-{{ $nodeType }}-data{{ $.Values.elasticsearch.nameSuffix }} description: "Elasticsearch {{ $nodeType }} volume" spec: - fileSystemType: {{ $.Values.elasticsearch.volume.fileSystemType }} - initialCapacity: {{ index $.Values.elasticsearch.volume $nodeType "initialCapacity" }} - performanceClass: {{ $.Values.elasticsearch.volume.performanceClass }} + fileSystemType: {{ $config.volume.fileSystemType | default $.Values.elasticsearch.volume.fileSystemType }} + initialCapacity: {{ $config.volume.initialCapacity }} + performanceClass: {{ $config.volume.performanceClass | default $.Values.elasticsearch.volume.performanceClass }} {{- end }} {{- end }} diff --git a/examples/elastic/helm/templates/workload.yaml b/examples/elastic/helm/templates/workload.yaml index fe4503f..5b29bf7 100644 --- a/examples/elastic/helm/templates/workload.yaml +++ b/examples/elastic/helm/templates/workload.yaml @@ -2,7 +2,7 @@ {{- if $config.enabled }} --- kind: workload -name: es-{{ $nodeType }} +name: es-{{ $nodeType }}{{ $.Values.elasticsearch.nameSuffix }} description: "Elasticsearch {{ $nodeType }} node" spec: type: stateful @@ -19,6 +19,15 @@ spec: env: - name: NODE_ROLES value: "[{{ $config.roles }}]" + {{- if $config.jvm }} + - name: ES_JAVA_OPTS + value: >- + -Xms{{ $config.jvm.heapSize }} + -Xmx{{ $config.jvm.heapSize }} + -XX:MaxDirectMemorySize={{ $config.jvm.maxDirectMemorySize }} + -XX:InitiatingHeapOccupancyPercent={{ $config.jvm.initiatingHeapOccupancyPercent }} + -XX:G1ReservePercent={{ $config.jvm.g1ReservePercent }} + {{- end }} livenessProbe: exec: command: @@ -50,7 +59,7 @@ spec: volumes: - path: /usr/share/elasticsearch/data recoveryPolicy: retain - uri: 'cpln://volumeset/es-{{ $nodeType }}-data' + uri: 'cpln://volumeset/es-{{ $nodeType }}-data{{ $.Values.elasticsearch.nameSuffix }}' - path: /usr/share/elasticsearch/config-custom/elasticsearch.yml recoveryPolicy: retain uri: 'cpln://secret/elasticsearch-config-{{ $.Values.cpln.gvc }}' diff --git a/examples/elastic/helm/values.yaml b/examples/elastic/helm/values.yaml index f5e6db5..e90c84d 100644 --- a/examples/elastic/helm/values.yaml +++ b/examples/elastic/helm/values.yaml @@ -11,14 +11,8 @@ elasticsearch: name: elasticsearch volume: - fileSystemType: ext4 + fileSystemType: xfs performanceClass: general-purpose-ssd - master: - initialCapacity: 10 - data: - initialCapacity: 20 - ingest: - initialCapacity: 10 config: clusterName: "elasticsearch-cluster" @@ -27,42 +21,87 @@ elasticsearch: allowMmap: false security: enabled: false + recovery: + incomingRecoveries: 50 + outgoingRecoveries: 50 + maxBytesPerSec: "2000mb" + discovery: + initialMasterNodes: ["es-master-0.es-master", "es-master-1.es-master", "es-master-2.es-master"] + zen: + minimumMasterNodes: 2 + pingTimeout: 10s + joinTimeout: 30s + cluster: + initialMasterNodes: ["es-master-0.es-master", "es-master-1.es-master", "es-master-2.es-master"] + waitForActiveShards: "majority" + network: + host: "0.0.0.0" + publish_host: "${HOSTNAME}.${WORKLOAD_NAME}" + bootstrap: + memory_lock: true nodes: master: enabled: true replicas: 3 - roles: master # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html resources: - cpu: 2000m - memory: 4Gi + cpu: "3000m" + memory: "16Gi" + roles: "master,remote_cluster_client" + volume: + fileSystemType: "xfs" + size: "100Gi" + initialCapacity: 100 data: enabled: true replicas: 3 - roles: data # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html resources: - cpu: 4000m - memory: 16Gi + cpu: "4000m" + memory: "16Gi" + roles: "data,data_content,data_hot,data_warm,data_cold" + volume: + fileSystemType: "xfs" + size: "100Gi" + initialCapacity: 100 + ingest: enabled: true replicas: 2 - roles: ingest # Comma separated list https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html + roles: "ingest,remote_cluster_client" resources: - cpu: 2000m - memory: 8Gi + cpu: "3000m" + memory: "16Gi" + volume: + initialCapacity: 10 + fileSystemType: xfs + performanceClass: general-purpose-ssd + + coordinator: + enabled: true + replicas: 2 + roles: "remote_cluster_client" + resources: + cpu: "3000m" + memory: "16Gi" + volume: + initialCapacity: 10 + fileSystemType: xfs + performanceClass: general-purpose-ssd probes: liveness: - initialDelay: 60 - period: 15 - timeout: 3 + initialDelay: 120 + period: 30 + timeout: 5 readiness: - initialDelay: 10 - period: 5 - timeout: 3 + initialDelay: 30 + period: 10 + timeout: 5 ports: - number: 9200 protocol: http - number: 9300 - protocol: tcp \ No newline at end of file + protocol: tcp + + nameSuffix: "" \ No newline at end of file