1b5e305f253710c02f054ff74fe329d42c22d31e
[oom.git] / kubernetes / common / elasticsearch / components / master / templates / statefulset.yaml
1 # Copyright © 2020 Bitnami, AT&T, Amdocs, Bell Canada, highstreet technologies
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 apiVersion: apps/v1
16 kind: StatefulSet
17 {{ $role := "master" -}}
18 {{ $suffix := $role -}}
19 {{ $labels := (dict "role" $role "discovery" (include "elasticsearch.clustername" .)) -}}
20 metadata: {{- include "common.resourceMetadata" (dict "suffix" $suffix "labels" $labels "dot" . )| nindent 2 }}
21 spec:
22   updateStrategy:
23     type: {{ .Values.updateStrategy.type }}
24     {{- if (eq "OnDelete" .Values.updateStrategy.type) }}
25     rollingUpdate: null
26     {{- end }}
27   selector: {{- include "common.selectors" (dict "matchLabels" $labels "dot" .)| nindent 4 }}
28   serviceName: {{ include "common.fullname" . }}-master
29   replicas: {{ .Values.replicaCount }}
30   template:
31     metadata: {{- include "common.templateMetadata" (dict "labels" $labels "dot" .) | nindent 6 }}
32     spec:
33 {{- include "elasticsearch.imagePullSecrets" . | nindent 6 }}
34       {{- if .Values.affinity }}
35       affinity: {{- include "common.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
36       {{- end }}
37       {{- if .Values.nodeSelector }}
38       nodeSelector: {{- include "common.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
39       {{- end }}
40       {{- if .Values.tolerations }}
41       tolerations: {{- include "common.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
42       {{- end }}
43       serviceAccountName: {{ template "elasticsearch.serviceAccountName" . }}
44       {{- if .Values.securityContext.enabled }}
45       securityContext:
46         fsGroup: {{ .Values.securityContext.fsGroup }}
47       {{- end }}
48       {{- if or .Values.sysctlImage.enabled (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
49       initContainers:
50         {{- if .Values.sysctlImage.enabled }}
51         ## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
52         - name: sysctl
53           image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
54           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
55           command:
56             - /bin/sh
57             - -c
58             - |
59               set -o errexit
60               set -o pipefail
61               set -o nounset
62               sysctl -w vm.max_map_count=262144 && sysctl -w fs.file-max=65536
63           securityContext:
64             privileged: true
65         {{- end }}
66         {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
67         - name: volume-permissions
68           image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
69           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
70           command:
71             - /bin/sh
72             - -c
73             - |
74               chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} //bitnami/elasticsearch/data
75           securityContext:
76             runAsUser: 0
77           {{- if .Values.volumePermissions.resource }}
78           resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
79           {{- end }}
80           volumeMounts:
81             - name: data
82               mountPath: "/bitnami/elasticsearch/data"
83         {{- end }}
84       {{- end }}
85       containers:
86         - name: {{ include "common.name" . }}-master
87           image: {{ printf "%s/%s:%s" (include "common.repository" .)  .Values.image.imageName  .Values.image.tag }}
88           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
89           {{- if .Values.securityContext.enabled }}
90           securityContext:
91             runAsUser: {{ .Values.securityContext.runAsUser }}
92           {{- end }}
93           env:
94             - name: BITNAMI_DEBUG
95               value: {{ ternary "true" "false" .Values.image.debug | quote }}
96             - name: ELASTICSEARCH_CLUSTER_NAME
97               value: {{ include "elasticsearch.clustername" . }}
98             - name: ELASTICSEARCH_CLUSTER_HOSTS
99               value: {{ include "common.name" . }}-discovery
100             - name: ELASTICSEARCH_CLUSTER_MASTER_HOSTS
101               {{- $elasticsearchMasterFullname := printf "%s-%s" (include "common.fullname" . ) "master" }}
102               {{- $replicas := int .Values.replicaCount }}
103               value: {{range $i, $e := until $replicas }}{{ $elasticsearchMasterFullname }}-{{ $e }} {{ end }}
104             - name: ELASTICSEARCH_MINIMUM_MASTER_NODES
105               value: {{ add (div .Values.replicaCount 2) 1 | quote }}
106             {{- if .Values.plugins }}
107             - name: ELASTICSEARCH_PLUGINS
108               value: {{ .Values.plugins | quote }}
109             {{- end }}
110             - name: ELASTICSEARCH_HEAP_SIZE
111               value: {{ .Values.heapSize | quote }}
112             - name: ELASTICSEARCH_IS_DEDICATED_NODE
113               value: {{ .Values.dedicatednode | quote }}
114             - name: ELASTICSEARCH_NODE_TYPE
115               value: "master"
116           ports: {{- include "common.containerPorts" . |indent 12 }}
117           {{- if .Values.livenessProbe.enabled }}
118           livenessProbe:
119             initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
120             periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
121             timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
122             successThreshold: {{ .Values.livenessProbe.successThreshold }}
123             failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
124             httpGet:
125               path: /_cluster/health?local=true
126               port: 9200
127           {{- end }}
128           {{- if .Values.readinessProbe.enabled }}
129           readinessProbe:
130             initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
131             periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
132             timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
133             successThreshold: {{ .Values.livenessProbe.successThreshold }}
134             failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
135             httpGet:
136               path: /_cluster/health?local=true
137               port: 9200
138           {{- end }}
139           {{- if .Values.resources }}
140           resources: {{- toYaml .Values.resources | nindent 12 }}
141           {{- end }}
142           volumeMounts:
143             {{- if .Values.config }}
144             - mountPath: /opt/bitnami/elasticsearch/config/elasticsearch.yml
145               name: config
146               subPath: elasticsearch.yml
147             {{- end }}
148             - name: data
149               mountPath: /bitnami/elasticsearch/data
150             {{- if .Values.extraVolumeMounts }}
151             {{- toYaml .Values.extraVolumeMounts | nindent 12 }}
152             {{- end }}
153       volumes:
154         {{- if .Values.config }}
155         - name: config
156           configMap:
157             name: {{ include "common.fullname" . }}
158         {{- end }}
159         {{- if .Values.extraVolumes }}
160         {{- toYaml .Values.extraVolumes | nindent 8 }}
161         {{- end }}
162 {{- if not .Values.persistence.enabled }}
163         - name: "data"
164           emptyDir: {}
165 {{- else }}
166   volumeClaimTemplates:
167     - metadata:
168         name: "data"
169         {{- if .Values.persistence.annotations }}
170         annotations: {{- toYaml .Values.persistence.annotations | nindent 10 }}
171         {{- end }}
172       spec:
173         accessModes:
174           - {{ .Values.persistence.accessMode }}
175         storageClassName: {{ include "common.storageClass" (dict "dot" . "suffix" .Values.persistence.suffix) }}
176         resources:
177           requests:
178             storage: {{ .Values.persistence.size | quote }}
179 {{- end }}