deployment.yaml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. {{- $_ := set .Values "nextcloudDbHost" (include "common.names.fullname" $postgres_values) -}} {{/* Temprary store it on values to display it on NOTES */}}
  77. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }}
  78. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }}
  79. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_DATA_DIR" "value" .Values.nextcloud.datadir) }}
  80. {{ $envList = mustAppend $envList (dict "name" "PHP_UPLOAD_LIMIT" "value" (printf "%vG" (.Values.nextcloud.max_upload_size | default 3))) }}
  81. {{ $envList = mustAppend $envList (dict "name" "PHP_MEMORY_LIMIT" "value" (printf "%vM" (.Values.nextcloud.php_memory_limit | default 512))) }}
  82. {{ if eq (include "nginx.certAvailable" .) "true" }}
  83. {{ $envList = mustAppend $envList (dict "name" "APACHE_DISABLE_REWRITE_IP" "value" "1") }}
  84. {{ if and .Values.nextcloud.host .Values.service.nodePort }}
  85. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEHOST" "value" (printf "%v:%v" .Values.nextcloud.host .Values.service.nodePort)) }}
  86. {{ end }}
  87. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEPROTOCOL" "value" "https") }}
  88. {{ $envList = mustAppend $envList (dict "name" "TRUSTED_PROXIES" "value" "127.0.0.1") }}
  89. {{ end }}
  90. {{ $hostName := .Values.nextcloud.host }}
  91. {{ if .Values.useServiceNameForHost }}
  92. {{ $hostName = (include "common.names.fullname" .) }}
  93. {{ end }}
  94. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_TRUSTED_DOMAINS" "value" $hostName) }}
  95. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_USER" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-username") }}
  96. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_PASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-password") }}
  97. {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }}
  98. ports:
  99. - name: http
  100. containerPort: 80
  101. protocol: TCP
  102. livenessProbe:
  103. httpGet:
  104. path: /status.php
  105. port: http
  106. httpHeaders:
  107. - name: Host
  108. value: localhost
  109. initialDelaySeconds: 10
  110. periodSeconds: 10
  111. timeoutSeconds: 5
  112. failureThreshold: 5
  113. successThreshold: 1
  114. readinessProbe:
  115. httpGet:
  116. path: /status.php
  117. port: http
  118. httpHeaders:
  119. - name: Host
  120. value: localhost
  121. initialDelaySeconds: 10
  122. periodSeconds: 10
  123. timeoutSeconds: 5
  124. failureThreshold: 5
  125. successThreshold: 1
  126. startupProbe:
  127. {{ $cmds := list }}
  128. {{ if .Values.nextcloud.install_ffmpeg }}
  129. {{ $cmds = mustAppend $cmds "ffmpeg" }}
  130. {{ end }}
  131. {{ if .Values.nextcloud.install_smbclient }}
  132. {{ $cmds = mustAppend $cmds "smbclient" }}
  133. {{ end }}
  134. {{ if $cmds }}
  135. exec:
  136. command:
  137. - /bin/sh
  138. - -c
  139. - |
  140. commands_to_check={{ join " " $cmds }}
  141. for comm in $commands_to_check; do
  142. if ! command -v $comm /dev/null 2>&1; then
  143. echo "Command $comm not found"
  144. exit 1
  145. fi
  146. done
  147. {{ else }}
  148. httpGet:
  149. path: /status.php
  150. port: http
  151. httpHeaders:
  152. - name: Host
  153. value: localhost
  154. {{ end }}
  155. initialDelaySeconds: 60
  156. periodSeconds: 5
  157. timeoutSeconds: 2
  158. failureThreshold: 120
  159. successThreshold: 1
  160. volumeMounts:
  161. - name: nextcloud-data
  162. mountPath: /var/www/
  163. subPath: "root"
  164. - name: nextcloud-data
  165. mountPath: /var/www/html
  166. subPath: "html"
  167. - name: nextcloud-data
  168. mountPath: {{ .Values.nextcloud.datadir }}
  169. subPath: "data"
  170. - name: nextcloud-data
  171. mountPath: /var/www/html/config
  172. subPath: "config"
  173. - name: nextcloud-data
  174. mountPath: /var/www/html/custom_apps
  175. subPath: "custom_apps"
  176. - name: nextcloud-data
  177. mountPath: /var/www/tmp
  178. subPath: "tmp"
  179. - name: nextcloud-data
  180. mountPath: /var/www/html/themes
  181. subPath: "themes"
  182. - name: nextcloud-configuration
  183. # We use -z-99 to ensure that this file is loaded
  184. # after the default opcache file nextcloud provides.
  185. mountPath: /usr/local/etc/php/conf.d/opcache-z-99.ini
  186. subPath: opcache.ini
  187. - name: nextcloud-configuration
  188. # We use -z-99 to ensure that this file is loaded
  189. # after the default php config file nextcloud provides.
  190. mountPath: /usr/local/etc/php/conf.d/nextcloud-z-99.ini
  191. subPath: php.ini
  192. - name: nextcloud-configuration
  193. # https://github.com/nextcloud/docker/issues/1796
  194. mountPath: /etc/apache2/conf-enabled/limitrequestbody.conf
  195. subPath: limitrequestbody.conf
  196. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  197. - name: extrappvolume-{{ $index }}
  198. mountPath: {{ $hostPathConfiguration.mountPath }}
  199. {{ end }}
  200. {{ if $cmds }}
  201. lifecycle:
  202. postStart:
  203. exec:
  204. command:
  205. - /bin/sh
  206. - -c
  207. - |
  208. echo "Installing {{ join " " $cmds }}..."
  209. apt update && \
  210. apt install -y --no-install-recommends \
  211. {{ join " " $cmds }} || echo "Failed to install binary/binaries"
  212. echo "Finished."
  213. {{ end }}
  214. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  215. volumes:
  216. - name: nextcloud-configuration
  217. configMap:
  218. defaultMode: 0755
  219. name: "nextcloud-configuration"
  220. - name: nginx-configuration
  221. configMap:
  222. defaultMode: 0700
  223. name: "nginx-configuration"
  224. {{ include "nginx.tlsKeysVolume" . | nindent 8 }}
  225. {{ if .Values.appVolumeMounts }}
  226. {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  227. {{ end }}
  228. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  229. - name: extrappvolume-{{ $index }}
  230. hostPath:
  231. path: {{ $hostPathConfiguration.hostPath }}
  232. {{ end }}
  233. # Will mount configuration files as www-data (id: 33) for nextcloud
  234. securityContext:
  235. fsGroup: 33