deployment.yaml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {{ include "common.storage.hostPathValidate" .Values }}
  2. {{ $postgres_values := (. | mustDeepCopy) }}
  3. {{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }}
  4. {{ include "common.deployment.common_config" . | nindent 0 }}
  5. spec: {{ include "common.deployment.common_spec" . | nindent 2 }}
  6. template: {{ include "common.deployment.pod.metadata" . | nindent 4 }}
  7. spec:
  8. initContainers:
  9. - name: init-postgresdb
  10. image: {{ template "postgres.imageName" . }}
  11. command: ['sh', '-c', "until pg_isready -U $POSTGRES_USER -d {{ include "postgres.DatabaseName" .Values }} -h {{ template "common.names.fullname" $postgres_values }}; do echo waiting for postgres; sleep 2; done"]
  12. imagePullPolicy: {{ .Values.image.pullPolicy }}
  13. env: {{ include "postgres.envVariableConfiguration" $postgres_values | nindent 10 }}
  14. containers:
  15. {{ if eq (include "nginx.certAvailable" .) "true" }}
  16. - name: nginx
  17. {{ include "common.containers.imageConfig" .Values.nginx.image | nindent 8 }}
  18. volumeMounts:
  19. - name: nginx-configuration
  20. mountPath: /etc/nginx/nginx.conf
  21. subPath: nginx.conf
  22. {{ include "nginx.tlsKeysVolumeMount" . | nindent 10 }}
  23. ports:
  24. - name: nginx-http
  25. containerPort: 8000
  26. protocol: TCP
  27. - name: nginx-https
  28. containerPort: {{ .Values.service.nodePort }}
  29. protocol: TCP
  30. livenessProbe:
  31. httpGet:
  32. scheme: HTTPS
  33. path: /status.php
  34. port: {{ .Values.service.nodePort }}
  35. httpHeaders:
  36. - name: Host
  37. value: localhost
  38. initialDelaySeconds: 10
  39. periodSeconds: 10
  40. timeoutSeconds: 5
  41. failureThreshold: 5
  42. successThreshold: 1
  43. readinessProbe:
  44. httpGet:
  45. scheme: HTTPS
  46. path: /status.php
  47. port: {{ .Values.service.nodePort }}
  48. httpHeaders:
  49. - name: Host
  50. value: localhost
  51. initialDelaySeconds: 10
  52. periodSeconds: 10
  53. timeoutSeconds: 5
  54. failureThreshold: 5
  55. successThreshold: 2
  56. startupProbe:
  57. httpGet:
  58. scheme: HTTPS
  59. path: /status.php
  60. port: {{ .Values.service.nodePort }}
  61. httpHeaders:
  62. - name: Host
  63. value: localhost
  64. initialDelaySeconds: 30
  65. periodSeconds: 5
  66. timeoutSeconds: 2
  67. failureThreshold: 60
  68. successThreshold: 1
  69. {{ end }}
  70. - name: {{ .Chart.Name }}
  71. {{ include "common.resources.limitation" . | nindent 8 }}
  72. {{ include "common.containers.imageConfig" .Values.image | nindent 8 }}
  73. env: {{ include "postgres.envVariableConfiguration" $postgres_values | nindent 10 }}
  74. {{ $secretName := (include "common.names.fullname" .) }}
  75. {{ $envList := (default list .Values.environmentVariables) }}
  76. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }}
  77. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }}
  78. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_DATA_DIR" "value" .Values.nextcloud.datadir) }}
  79. {{ $envList = mustAppend $envList (dict "name" "PHP_UPLOAD_LIMIT" "value" (printf "%vG" (.Values.nextcloud.max_upload_size | default 3))) }}
  80. {{ if eq (include "nginx.certAvailable" .) "true" }}
  81. {{ $envList = mustAppend $envList (dict "name" "APACHE_DISABLE_REWRITE_IP" "value" "1") }}
  82. {{ if and .Values.nextcloud.host .Values.service.nodePort }}
  83. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEHOST" "value" (printf "%v:%v" .Values.nextcloud.host .Values.service.nodePort)) }}
  84. {{ end }}
  85. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEPROTOCOL" "value" "https") }}
  86. {{ $envList = mustAppend $envList (dict "name" "TRUSTED_PROXIES" "value" "127.0.0.1") }}
  87. {{ end }}
  88. {{ $hostName := .Values.nextcloud.host }}
  89. {{ if .Values.useServiceNameForHost }}
  90. {{ $hostName = (include "common.names.fullname" .) }}
  91. {{ end }}
  92. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_TRUSTED_DOMAINS" "value" $hostName) }}
  93. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_USER" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-username") }}
  94. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_PASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-password") }}
  95. {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }}
  96. ports:
  97. - name: http
  98. containerPort: 80
  99. protocol: TCP
  100. livenessProbe:
  101. httpGet:
  102. path: /status.php
  103. port: http
  104. httpHeaders:
  105. - name: Host
  106. value: localhost
  107. initialDelaySeconds: 10
  108. periodSeconds: 10
  109. timeoutSeconds: 5
  110. failureThreshold: 5
  111. successThreshold: 1
  112. readinessProbe:
  113. httpGet:
  114. path: /status.php
  115. port: http
  116. httpHeaders:
  117. - name: Host
  118. value: localhost
  119. initialDelaySeconds: 10
  120. periodSeconds: 10
  121. timeoutSeconds: 5
  122. failureThreshold: 5
  123. successThreshold: 1
  124. startupProbe:
  125. {{ $cmds := list }}
  126. {{ if .Values.nextcloud.install_ffmpeg }}
  127. {{ $cmds = mustAppend $cmds "ffmpeg" }}
  128. {{ end }}
  129. {{ if .Values.nextcloud.install_smbclient }}
  130. {{ $cmds = mustAppend $cmds "smbclient" }}
  131. {{ end }}
  132. {{ if $cmds }}
  133. exec:
  134. command:
  135. - /bin/sh
  136. - -c
  137. - |
  138. commands_to_check={{ join " " $cmds }}
  139. for comm in $commands_to_check; do
  140. if ! command -v $comm /dev/null 2>&1; then
  141. echo "Command $comm not found"
  142. exit 1
  143. fi
  144. done
  145. {{ else }}
  146. httpGet:
  147. path: /status.php
  148. port: http
  149. httpHeaders:
  150. - name: Host
  151. value: localhost
  152. {{ end }}
  153. initialDelaySeconds: 60
  154. periodSeconds: 5
  155. timeoutSeconds: 2
  156. failureThreshold: 120
  157. successThreshold: 1
  158. volumeMounts:
  159. - name: nextcloud-data
  160. mountPath: /var/www/
  161. subPath: "root"
  162. - name: nextcloud-data
  163. mountPath: /var/www/html
  164. subPath: "html"
  165. - name: nextcloud-data
  166. mountPath: {{ .Values.nextcloud.datadir }}
  167. subPath: "data"
  168. - name: nextcloud-data
  169. mountPath: /var/www/html/config
  170. subPath: "config"
  171. - name: nextcloud-data
  172. mountPath: /var/www/html/custom_apps
  173. subPath: "custom_apps"
  174. - name: nextcloud-data
  175. mountPath: /var/www/tmp
  176. subPath: "tmp"
  177. - name: nextcloud-data
  178. mountPath: /var/www/html/themes
  179. subPath: "themes"
  180. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  181. - name: extrappvolume-{{ $index }}
  182. mountPath: {{ $hostPathConfiguration.mountPath }}
  183. {{ end }}
  184. {{ if $cmds }}
  185. lifecycle:
  186. postStart:
  187. exec:
  188. command:
  189. - /bin/sh
  190. - -c
  191. - |
  192. echo "Installing {{ join " " $cmds }}..."
  193. apt update && \
  194. apt install -y --no-install-recommends \
  195. {{ join " " $cmds }} || echo "Failed to install binary/binaries"
  196. echo "Finished."
  197. {{ end }}
  198. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  199. volumes:
  200. - name: nginx-configuration
  201. configMap:
  202. defaultMode: 0700
  203. name: "nginx-configuration"
  204. {{ include "nginx.tlsKeysVolume" . | nindent 8 }}
  205. {{ if .Values.appVolumeMounts }}
  206. {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  207. {{ end }}
  208. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  209. - name: extrappvolume-{{ $index }}
  210. hostPath:
  211. path: {{ $hostPathConfiguration.hostPath }}
  212. {{ end }}
  213. # Will mount configuration files as www-data (id: 33) for nextcloud
  214. securityContext:
  215. fsGroup: 33