deployment.yaml 9.9 KB

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