data-statefulset.yaml 6.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  labels:
    app: {{ template "elasticsearch.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    component: "{{ .Values.data.name }}"
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "elasticsearch.data.fullname" . }}
spec:
  serviceName: {{ template "elasticsearch.data.fullname" . }}
  replicas: {{ .Values.data.replicas }}
  template:
    metadata:
      labels:
        app: {{ template "elasticsearch.name" . }}
        component: "{{ .Values.data.name }}"
        release: {{ .Release.Name }}
        {{- if .Values.data.podAnnotations }}
      annotations:
{{ toYaml .Values.data.podAnnotations | indent 8 }}
        {{- end }}
    spec:
{{- if .Values.data.priorityClassName }}
      priorityClassName: "{{ .Values.data.priorityClassName }}"
{{- end }}
      securityContext:
        fsGroup: 1000
      {{- if eq .Values.data.antiAffinity "hard" }}
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - topologyKey: "kubernetes.io/hostname"
              labelSelector:
                matchLabels:
                  app: "{{ template "elasticsearch.name" . }}"
                  release: "{{ .Release.Name }}"
                  component: "{{ .Values.data.name }}"
      {{- else if eq .Values.data.antiAffinity "soft" }}
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  app: "{{ template "elasticsearch.name" . }}"
                  release: "{{ .Release.Name }}"
                  component: "{{ .Values.data.name }}"
      {{- end }}
{{- if .Values.data.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.data.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.data.tolerations }}
      tolerations:
{{ toYaml .Values.data.tolerations | indent 8 }}
{{- end }}
      initContainers:
      # see https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
      # and https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#mlockall
      - name: "sysctl"
        image: "busybox"
        imagePullPolicy: "Always"
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      - name: "chown"
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        command:
        - /bin/bash
        - -c
        - chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data &&
          chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/logs
        securityContext:
          runAsUser: 0
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: data
      containers:
      - name: elasticsearch
        env:
        - name: DISCOVERY_SERVICE
87
          value: {{ template "elasticsearch.fullname" . }}-discovery
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        - name: NODE_MASTER
          value: "false"
        - name: PROCESSORS
          valueFrom:
            resourceFieldRef:
              resource: limits.cpu
        - name: ES_JAVA_OPTS
          value: "-Djava.net.preferIPv4Stack=true -Xms{{ .Values.data.heapSize }} -Xmx{{ .Values.data.heapSize }}"
        {{- range $key, $value :=  .Values.cluster.env }}
        - name: {{ $key }}
          value: {{ $value | quote }}
        {{- end }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        ports:
        - containerPort: 9300
          name: transport
{{ if .Values.data.exposeHttp }}
        - containerPort: 9200
          name: http
{{ end }}
        resources:
{{ toYaml .Values.data.resources | indent 12 }}
        readinessProbe:
          httpGet:
            path: /_cluster/health?local=true
            port: 9200
          initialDelaySeconds: 5
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: data
        - mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          name: config
          subPath: elasticsearch.yml
{{- if hasPrefix "2." .Values.image.tag }}
        - mountPath: /usr/share/elasticsearch/config/logging.yml
          name: config
          subPath: logging.yml
{{- end }}
{{- if hasPrefix "5." .Values.image.tag }}
        - mountPath: /usr/share/elasticsearch/config/log4j2.properties
          name: config
          subPath: log4j2.properties
{{- end }}
        - name: config
          mountPath: /pre-stop-hook.sh
          subPath: pre-stop-hook.sh
        - name: config
          mountPath: /post-start-hook.sh
          subPath: post-start-hook.sh
138 139 140 141 142 143
{{- if .Values.cluster.keystoreSecret }}
        - name: keystore
          mountPath: "/usr/share/elasticsearch/config/elasticsearch.keystore"
          subPath: elasticsearch.keystore
          readOnly: true
{{- end }}
144 145 146 147 148 149 150 151
        lifecycle:
          preStop:
            exec:
              command: ["/bin/bash","/pre-stop-hook.sh"]
          postStart:
            exec:
              command: ["/bin/bash","/post-start-hook.sh"]
      terminationGracePeriodSeconds: {{ .Values.data.terminationGracePeriodSeconds }}
152 153 154 155 156 157
{{- if .Values.image.pullSecrets }}
      imagePullSecrets:
      {{- range $pullSecret := .Values.image.pullSecrets }}
        - name: {{ $pullSecret }}
      {{- end }}
{{- end }}
158 159 160 161
      volumes:
      - name: config
        configMap:
          name: {{ template "elasticsearch.fullname" . }}
162 163 164 165 166
{{- if .Values.cluster.keystoreSecret }}
      - name: keystore
        secret:
          secretName: {{ .Values.cluster.keystoreSecret }}
{{- end }}
167 168 169
  {{- if not .Values.data.persistence.enabled }}
      - name: data
        emptyDir: {}
170 171 172 173
  {{- end }}
  updateStrategy:
    type: {{ .Values.data.updateStrategy.type }}
  {{- if .Values.data.persistence.enabled }}
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  volumeClaimTemplates:
  - metadata:
      name: {{ .Values.data.persistence.name }}
    spec:
      accessModes:
        - {{ .Values.data.persistence.accessMode | quote }}
    {{- if .Values.data.persistence.storageClass }}
    {{- if (eq "-" .Values.data.persistence.storageClass) }}
      storageClassName: ""
    {{- else }}
      storageClassName: "{{ .Values.data.persistence.storageClass }}"
    {{- end }}
    {{- end }}
      resources:
        requests:
          storage: "{{ .Values.data.persistence.size }}"
  {{- end }}