deployment.yaml 9.4 KB

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