readreplicas-statefulset.yaml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. {{- $saName := print (include "neo4j.fullname" .) "-sa" -}}
  2. {{- if not .Values.core.standalone }}
  3. # The ReadReplica deployment only happens for clustered installs.
  4. apiVersion: "apps/v1"
  5. kind: StatefulSet
  6. metadata:
  7. name: "{{ template "neo4j.replica.fullname" . }}"
  8. labels:
  9. app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
  10. app.kubernetes.io/instance: {{ .Release.Name | quote }}
  11. helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
  12. app.kubernetes.io/name: {{ template "neo4j.name" . }}
  13. app.kubernetes.io/component: replica
  14. spec:
  15. podManagementPolicy: Parallel
  16. serviceName: "{{ template "neo4j.replica.fullname" . }}"
  17. {{- if not .Values.readReplica.autoscaling.enabled }}
  18. replicas: {{ .Values.readReplica.numberOfServers }}
  19. {{- end }}
  20. selector:
  21. matchLabels:
  22. app.kubernetes.io/name: {{ template "neo4j.name" . }}
  23. app.kubernetes.io/instance: {{ .Release.Name | quote }}
  24. app.kubernetes.io/component: replica
  25. template:
  26. metadata:
  27. labels:
  28. app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
  29. app.kubernetes.io/instance: {{ .Release.Name | quote }}
  30. helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  31. app.kubernetes.io/name: {{ template "neo4j.name" . }}
  32. app.kubernetes.io/component: replica
  33. {{- range $key, $value := .Values.podLabels }}
  34. {{ $key }}: "{{ $value }}"
  35. {{- end }}
  36. {{- if .Values.podAnnotations }}
  37. {{- with .Values.podAnnotations }}
  38. annotations: {{- toYaml . | nindent 8 }}
  39. {{- end }}
  40. {{- end }}
  41. spec:
  42. serviceAccountName: {{ default $saName .Values.serviceAccount.name }}
  43. automountServiceAccountToken: true
  44. # High value permits checkpointing on Neo4j shutdown. See: https://neo4j.com/developer/kb/checkpointing-and-log-pruning-interactions/
  45. terminationGracePeriodSeconds: {{ .Values.readReplica.terminationGracePeriodSeconds }}
  46. containers:
  47. - name: neo4j
  48. image: "{{ .Values.image }}:{{ .Values.imageTag }}"
  49. imagePullPolicy: "{{ .Values.imagePullPolicy }}"
  50. securityContext:
  51. {{ toYaml .Values.containerSecurityContext | indent 10 }}
  52. # Most pod config is factored into a different configMap, which is user overrideable.
  53. envFrom:
  54. - configMapRef:
  55. name: {{ template "neo4j.commonConfig.fullname" . }}
  56. - configMapRef:
  57. name: {{ template "neo4j.replicaConfig.fullname" . }}
  58. {{- if .Values.readReplica.configMap }}
  59. - configMapRef:
  60. name: "{{ .Values.readReplica.configMap }}"
  61. {{- end }}
  62. {{- if .Values.readReplica.envFrom }}{{ toYaml .Values.readReplica.envFrom | nindent 10 }}{{- end }}
  63. env:
  64. {{- if .Values.authEnabled }}
  65. - name: NEO4J_SECRETS_PASSWORD
  66. valueFrom:
  67. secretKeyRef:
  68. {{- if .Values.existingPasswordSecret }}
  69. name: {{ .Values.existingPasswordSecret }}
  70. {{- else }}
  71. name: {{ template "neo4j.secrets.fullname" . }}
  72. {{- end}}
  73. key: {{ template "neo4j.secrets.key" . }}
  74. {{- end }}
  75. command:
  76. - "/bin/bash"
  77. - "-c"
  78. - |
  79. export replica_idx=$(hostname | sed 's|.*-||')
  80. # Processes key configuration elements and exports env vars we need.
  81. . /helm-init/init.sh
  82. # These settings are *not* overrideable, because they must match the addresses the
  83. # core members see to avoid akka rejections.
  84. export NEO4J_causal__clustering_discovery__advertised__address=$HOST:5000
  85. export NEO4J_causal__clustering_transaction__advertised__address=$HOST:6000
  86. export NEO4J_causal__clustering_raft__advertised__address=$HOST:7000
  87. export NEO4J_dbms_routing_advertised__address=$HOST:7688
  88. echo "Starting Neo4j READ_REPLICA $replica_idx on $HOST"
  89. exec /docker-entrypoint.sh "neo4j"
  90. ports:
  91. - containerPort: 5000
  92. name: tcp-discovery
  93. - containerPort: 7000
  94. name: tcp-raft
  95. - containerPort: 6000
  96. name: tcp-tx
  97. - containerPort: 7474
  98. name: tcp-browser
  99. - containerPort: 7687
  100. name: tcp-bolt
  101. - containerPort: 7688
  102. name: tcp-boltrouting
  103. {{- if .Values.metrics.prometheus.enabled }}
  104. - containerPort: 2004
  105. name: tcp-prometheus
  106. {{- end }}
  107. {{- if .Values.metrics.graphite.enabled }}
  108. - containerPort: 2003
  109. name: tcp-graphite
  110. {{- end }}
  111. {{- if .Values.metrics.jmx.enabled }}
  112. - containerPort: 3637
  113. name: jmx
  114. {{- end }}
  115. volumeMounts:
  116. - name: init-script
  117. mountPath: /helm-init
  118. - name: plugins
  119. mountPath: /plugins
  120. - name: datadir
  121. mountPath: "{{ .Values.readReplica.persistentVolume.mountPath }}"
  122. {{- if .Values.readReplica.persistentVolume.subPath }}
  123. subPath: {{ .Values.readReplica.persistentVolume.subPath }}
  124. {{- end }}
  125. {{- if .Values.readReplica.additionalVolumeMounts }}
  126. {{ toYaml .Values.readReplica.additionalVolumeMounts | indent 8}}
  127. {{- end }}
  128. startupProbe:
  129. {{ toYaml .Values.startupProbe | indent 10 }}
  130. readinessProbe:
  131. {{ toYaml .Values.readinessProbe | indent 10 }}
  132. livenessProbe:
  133. {{ toYaml .Values.livenessProbe | indent 10 }}
  134. resources:
  135. {{ toYaml .Values.readReplica.resources | indent 10 }}
  136. {{- if .Values.core.sidecarContainers }}
  137. {{ toYaml .Values.core.sidecarContainers | indent 6 }}
  138. {{- end }}
  139. initContainers:
  140. {{ if .Values.readReplica.restore.enabled }}
  141. - name: restore-from-backup
  142. image: "{{ .Values.readReplica.restore.image }}:{{ .Values.readReplica.restore.imageTag }}"
  143. imagePullPolicy: Always
  144. volumeMounts:
  145. - name: datadir
  146. mountPath: /data
  147. {{- if .Values.core.persistentVolume.subPath }}
  148. subPath: {{ .Values.core.persistentVolume.subPath }}
  149. {{- end }}
  150. {{- if and .Values.core.restore.enabled .Values.core.restore.secretName }}
  151. - name: credentials
  152. mountPath: /credentials
  153. readOnly: true
  154. {{- end }}
  155. env:
  156. - name: DATABASE
  157. value: {{ .Values.readReplica.restore.database }}
  158. - name: CLOUD_PROVIDER
  159. value: {{ .Values.readReplica.restore.cloudProvider }}
  160. - name: BUCKET
  161. value: {{ .Values.readReplica.restore.bucket }}
  162. - name: TIMESTAMP
  163. value: "{{ .Values.readReplica.restore.timestamp }}"
  164. - name: FORCE_OVERWRITE
  165. value: "{{ .Values.readReplica.restore.forceOverwrite }}"
  166. - name: PURGE_ON_COMPLETE
  167. value: "{{ .Values.readReplica.restore.purgeOnComplete }}"
  168. {{ end }}
  169. {{- if .Values.readReplica.initContainers }}
  170. {{ toYaml .Values.readReplica.initContainers | indent 6 }}
  171. {{- end }}
  172. {{- with .Values.nodeSelector }}
  173. nodeSelector:
  174. {{ toYaml . | indent 8 }}
  175. {{- end }}
  176. {{- with .Values.affinity }}
  177. affinity:
  178. {{ toYaml . | indent 8 }}
  179. {{- end }}
  180. {{- with .Values.tolerations }}
  181. tolerations:
  182. {{ toYaml . | indent 8 }}
  183. {{- end }}
  184. securityContext:
  185. {{ toYaml .Values.securityContext | indent 8 }}
  186. volumes:
  187. - name: init-script
  188. configMap:
  189. name: "{{ .Release.Name }}-init-script"
  190. {{- if and .Values.core.restore.enabled .Values.core.restore.secretName }}
  191. - name: credentials
  192. secret:
  193. secretName: {{ .Values.readReplica.restore.secretName }}
  194. items:
  195. - key: credentials
  196. path: credentials
  197. {{- end }}
  198. {{- if not .Values.readReplica.persistentVolume.enabled }}
  199. - name: datadir
  200. emptyDir: {}
  201. {{- end }}
  202. - name: plugins
  203. emptyDir: {}
  204. {{- if .Values.readReplica.additionalVolumes }}
  205. {{ toYaml .Values.readReplica.additionalVolumes | indent 8}}
  206. {{- end }}
  207. {{- if .Values.imagePullSecret }}
  208. imagePullSecrets:
  209. - name: {{ .Values.imagePullSecret }}
  210. {{- end -}}
  211. {{- if .Values.readReplica.persistentVolume.enabled }}
  212. volumeClaimTemplates:
  213. - metadata:
  214. name: datadir
  215. annotations:
  216. {{- if .Values.readReplica.persistentVolume.annotations }}
  217. {{ toYaml .Values.readReplica.persistentVolume.annotations | indent 12 }}
  218. {{- end }}
  219. spec:
  220. accessModes:
  221. - ReadWriteOnce
  222. {{- if .Values.readReplica.persistentVolume.storageClass }}
  223. {{- if (eq "-" .Values.readReplica.persistentVolume.storageClass) }}
  224. storageClassName: ""
  225. {{- else }}
  226. storageClassName: "{{ .Values.readReplica.persistentVolume.storageClass }}"
  227. {{- end }}
  228. {{- end }}
  229. resources:
  230. requests:
  231. storage: "{{ .Values.readReplica.persistentVolume.size }}"
  232. {{- end }}
  233. {{- end }} # if not standalone mode