From ed6779922b338470216f59f0c3a4e0c23f0a0548 Mon Sep 17 00:00:00 2001 From: Taehyun Kim Date: Mon, 21 Jan 2019 14:16:03 +0900 Subject: [PATCH 1/4] fix cluster outage, add masterService template --- elasticsearch/templates/_helpers.tpl | 8 +++ .../templates/master-announce-svc.yaml | 29 ++++++++++ elasticsearch/templates/statefulset.yaml | 54 +++++++++++++++++-- elasticsearch/values.yaml | 6 +-- 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 elasticsearch/templates/master-announce-svc.yaml diff --git a/elasticsearch/templates/_helpers.tpl b/elasticsearch/templates/_helpers.tpl index 192588d77..10fb73316 100755 --- a/elasticsearch/templates/_helpers.tpl +++ b/elasticsearch/templates/_helpers.tpl @@ -19,6 +19,14 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{ .Values.clusterName }}-{{ .Values.nodeGroup }} {{- end -}} +{{- define "masterService" -}} +{{- if empty .Values.masterService -}} +{{ template "uname" . }} +{{- else -}} +{{ .Values.masterService }} +{{- end -}} +{{- end -}} + {{- define "endpoints" -}} {{- $replicas := .replicas | int }} {{- $uname := printf "%s-%s" .clusterName .nodeGroup }} diff --git a/elasticsearch/templates/master-announce-svc.yaml b/elasticsearch/templates/master-announce-svc.yaml new file mode 100644 index 000000000..9f9f7529c --- /dev/null +++ b/elasticsearch/templates/master-announce-svc.yaml @@ -0,0 +1,29 @@ +{{ if eq .Values.roles.master "true" }} +{{- range $i := until (int .Values.replicas) }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ template "uname" $ }}-announce-{{ $i }} + labels: + heritage: {{ $.Release.Service | quote }} + release: {{ $.Release.Name | quote }} + chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" + app: "{{ template "uname" $ }}" + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" +spec: + type: ClusterIP + publishNotReadyAddresses: true + ports: + - name: transport + port: 9300 + targetPort: transport + selector: + heritage: {{ $.Release.Service | quote }} + release: {{ $.Release.Name | quote }} + chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" + app: "{{ template "uname" $ }}" + statefulset.kubernetes.io/pod-name: {{ template "masterService" $ }}-{{ $i }} +{{ end }} +{{ end }} diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 048256564..af4b90cf9 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -78,6 +78,8 @@ spec: secret: secretName: {{ .name }} {{- end }} + - name: config + emptyDir: {} {{- if .Values.esConfig }} - name: esconfig configMap: @@ -94,6 +96,39 @@ spec: privileged: true image: "{{ .Values.image }}:{{ .Values.imageTag }}" command: ["sysctl", "-w", "vm.max_map_count={{ .Values.sysctlVmMaxMapCount}}"] + - name: init-config + securityContext: + runAsUser: 0 + privileged: true + image: "{{ .Values.image }}:{{ .Values.imageTag }}" + command: + - /bin/bash + - -c + - |- + shopt -s nullglob dotglob + files=(/tmp/config/*) + if [ ${#files[@]} -gt 0 ]; then + cp -r /tmp/config/* /usr/share/elasticsearch/config/ + fi + + HOSTNAME="$(hostname)" + INDEX="${HOSTNAME##*-}" + + ENV_VAR_PREFIX=`echo {{ template "masterService" . }}-|awk '{print toupper($0)}'|sed 's/-/_/g'` + HOSTVAR="${ENV_VAR_PREFIX}ANNOUNCE_${INDEX}_SERVICE_HOST" + HOST="${!HOSTVAR}" + + if [ ! -f /usr/share/elasticsearch/config/elasticsearch.yml ]; then + echo "" > /usr/share/elasticsearch/config/elasticsearch.yml + fi; + echo "network.publish_host: ${HOST}" >> /usr/share/elasticsearch/config/elasticsearch.yml; + volumeMounts: + - name: config + mountPath: /usr/share/elasticsearch/config + {{- if .Values.esConfig }} + - name: esconfig + mountPath: /tmp/config + {{- end }} containers: - name: "{{ template "name" . }}" image: "{{ .Values.image }}:{{ .Values.imageTag }}" @@ -101,7 +136,7 @@ spec: readinessProbe: {{ toYaml .Values.readinessProbe | indent 10 }} exec: - command: + command: - sh - -c - | @@ -119,7 +154,7 @@ spec: fi curl -XGET -s -k --fail ${BASIC_AUTH} {{ .Values.protocol }}://127.0.0.1:{{ .Values.httpPort }}${path} } - + if [ -f "${START_FILE}" ]; then echo 'Elasticsearch is already running, lets check the node is healthy' http "/" @@ -155,7 +190,7 @@ spec: {{- end }} {{- end }} - name: discovery.zen.ping.unicast.hosts - value: "{{ .Values.masterService }}-headless" + value: "{{ template "masterService" . }}-headless" - name: cluster.name value: "{{ .Values.clusterName }}" - name: network.host @@ -180,7 +215,18 @@ spec: {{- end }} {{- end }} {{- range $path, $config := .Values.esConfig }} - - name: esconfig + - name: config mountPath: /usr/share/elasticsearch/config/{{ $path }} subPath: {{ $path }} + {{- end }} + {{- if not (empty .Values.esConfig) }} + {{- if not (hasKey .Values.esConfig "elasticsearch.yml") }} + - name: config + mountPath: /usr/share/elasticsearch/config/elasticsearch.yml + subPath: elasticsearch.yml + {{- end -}} + {{- else if (empty .Values.esConfig) }} + - name: config + mountPath: /usr/share/elasticsearch/config/elasticsearch.yml + subPath: elasticsearch.yml {{- end -}} diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 3561f8d1d..95e7a1b46 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -4,7 +4,7 @@ nodeGroup: "master" # The service that non master groups will try to connect to when joining the cluster # This should be set to clusterName + "-" + nodeGroup for your master group -masterService: "elasticsearch-master" +masterService: "" # Elasticsearch roles that will be applied to this nodeGroup # These will be set as environment variables. E.g. node.master=true @@ -37,7 +37,7 @@ extraEnvs: # A list of secrets and their paths to mount inside the pod # This is useful for mounting certificates for security and for mounting # the X-Pack license -secretMounts: +secretMounts: # - name: elastic-certificates # secretName: elastic-certificates # path: /usr/share/elasticsearch/config/certs @@ -67,7 +67,7 @@ volumeClaimTemplate: # By default this will make sure two pods don't end up on the same node # Changing this to a region would allow you to spread pods across regions -antiAffinityTopologyKey: "kubernetes.io/hostname" +antiAffinityTopologyKey: "kubernetes.io/hostname" # Hard means that by default pods will only be scheduled if there are enough nodes for them # and that they will never end up on the same node. Setting this to soft will do this "best effort" From 17fe76dccd898730073d65a42ae1e5ce55f23bd6 Mon Sep 17 00:00:00 2001 From: Taehyun Kim Date: Mon, 21 Jan 2019 14:24:01 +0900 Subject: [PATCH 2/4] bump chart version --- elasticsearch/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/Chart.yaml b/elasticsearch/Chart.yaml index c54de7cd2..d805cffbf 100755 --- a/elasticsearch/Chart.yaml +++ b/elasticsearch/Chart.yaml @@ -4,7 +4,7 @@ maintainers: - email: helm-charts@elastic.co name: Elastic name: elasticsearch -version: 6.5.4-alpha3 +version: 6.5.4-alpha4 appVersion: 6.5.4 sources: - https://github.com/elastic/elasticsearch From 1048ce37fa1c442b213724f3524e4b1a9c4c3629 Mon Sep 17 00:00:00 2001 From: Taehyun Kim Date: Tue, 29 Jan 2019 17:09:42 +0900 Subject: [PATCH 3/4] default value for secretMounts --- elasticsearch/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 8dd0004a5..0f4f3370a 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -37,7 +37,7 @@ extraEnvs: # A list of secrets and their paths to mount inside the pod # This is useful for mounting certificates for security and for mounting # the X-Pack license -secretMounts: +secretMounts: [] # - name: elastic-certificates # secretName: elastic-certificates # path: /usr/share/elasticsearch/config/certs From 95cf412f816295e9bc94733d90af6eb56824ab86 Mon Sep 17 00:00:00 2001 From: Taehyun Kim Date: Tue, 29 Jan 2019 17:09:54 +0900 Subject: [PATCH 4/4] use touch instead of echo "" --- elasticsearch/templates/statefulset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 1872e253d..41f50ad08 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -126,7 +126,7 @@ spec: HOST="${!HOSTVAR}" if [ ! -f /usr/share/elasticsearch/config/elasticsearch.yml ]; then - echo "" > /usr/share/elasticsearch/config/elasticsearch.yml + touch /usr/share/elasticsearch/config/elasticsearch.yml fi; echo "network.publish_host: ${HOST}" >> /usr/share/elasticsearch/config/elasticsearch.yml; volumeMounts: