deployment.yaml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. {{ include "common.storage.hostPathValidate" .Values }}
  2. {{ $postgres_values := (. | mustDeepCopy) }}
  3. {{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }}
  4. apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }}
  5. kind: Deployment
  6. metadata:
  7. name: {{ template "common.names.fullname" . }}-nc
  8. labels:
  9. app.kubernetes.io/name: {{ template "common.names.name" . }}
  10. app.kubernetes.io/instance: {{ .Release.Name }}
  11. spec:
  12. replicas: {{ (default 1 .Values.replicas) }}
  13. strategy:
  14. type: "Recreate"
  15. selector:
  16. matchLabels:
  17. app.kubernetes.io/name: {{ template "common.names.name" . }}
  18. app.kubernetes.io/instance: {{ .Release.Name }}
  19. template:
  20. metadata:
  21. name: {{ template "common.names.fullname" . }}
  22. labels:
  23. {{- include "common.labels.selectorLabels" . | nindent 8 }}
  24. annotations: {{ include "common.annotations" . | nindent 8 }}
  25. spec:
  26. initContainers:
  27. - name: init-postgresdb
  28. image: {{ template "postgres.imageName" . }}
  29. 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"]
  30. imagePullPolicy: {{ .Values.image.pullPolicy }}
  31. env: {{ include "postgres.envVariableConfiguration" $postgres_values | nindent 10 }}
  32. containers:
  33. {{ if eq (include "nginx.certAvailable" .) "true" }}
  34. - name: nginx
  35. {{ include "common.containers.imageConfig" .Values.nginx.image | nindent 8 }}
  36. volumeMounts:
  37. - name: nginx-configuration
  38. mountPath: /etc/nginx/nginx.conf
  39. subPath: nginx.conf
  40. {{ include "nginx.tlsKeysVolumeMount" . | nindent 10 }}
  41. ports:
  42. - name: nginx-http
  43. containerPort: 8000
  44. protocol: TCP
  45. - name: nginx-https
  46. containerPort: {{ .Values.service.nodePort }}
  47. protocol: TCP
  48. livenessProbe:
  49. httpGet:
  50. scheme: HTTPS
  51. path: /status.php
  52. port: {{ .Values.service.nodePort }}
  53. httpHeaders:
  54. - name: Host
  55. value: localhost
  56. initialDelaySeconds: 10
  57. periodSeconds: 10
  58. timeoutSeconds: 5
  59. failureThreshold: 5
  60. successThreshold: 1
  61. readinessProbe:
  62. httpGet:
  63. scheme: HTTPS
  64. path: /status.php
  65. port: {{ .Values.service.nodePort }}
  66. httpHeaders:
  67. - name: Host
  68. value: localhost
  69. initialDelaySeconds: 10
  70. periodSeconds: 10
  71. timeoutSeconds: 5
  72. failureThreshold: 5
  73. successThreshold: 2
  74. startupProbe:
  75. httpGet:
  76. scheme: HTTPS
  77. path: /status.php
  78. port: {{ .Values.service.nodePort }}
  79. httpHeaders:
  80. - name: Host
  81. value: localhost
  82. initialDelaySeconds: 30
  83. periodSeconds: 5
  84. timeoutSeconds: 2
  85. failureThreshold: 60
  86. successThreshold: 1
  87. {{ end }}
  88. - name: {{ .Chart.Name }}
  89. {{ include "common.resources.limitation" . | nindent 8 }}
  90. {{ include "common.containers.imageConfig" .Values.image | nindent 8 }}
  91. env: {{ include "postgres.envVariableConfiguration" $postgres_values | nindent 10 }}
  92. {{ $secretName := (include "common.names.fullname" .) }}
  93. {{ $envList := (default list .Values.environmentVariables) }}
  94. {{- $_ := set .Values "nextcloudDbHost" (include "common.names.fullname" $postgres_values) -}} {{/* Temprary store it on values to display it on NOTES */}}
  95. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }}
  96. {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }}
  97. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_DATA_DIR" "value" .Values.nextcloud.datadir) }}
  98. {{ $envList = mustAppend $envList (dict "name" "PHP_UPLOAD_LIMIT" "value" (printf "%vG" (.Values.nextcloud.max_upload_size | default 3))) }}
  99. {{ $envList = mustAppend $envList (dict "name" "PHP_MEMORY_LIMIT" "value" (printf "%vM" (.Values.nextcloud.php_memory_limit | default 512))) }}
  100. {{ if eq (include "nginx.certAvailable" .) "true" }}
  101. {{ $envList = mustAppend $envList (dict "name" "APACHE_DISABLE_REWRITE_IP" "value" "1") }}
  102. {{ if and .Values.nextcloud.host .Values.service.nodePort }}
  103. {{ if .Values.nginxConfig.useDifferentAccessPort }}
  104. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEHOST" "value" .Values.nextcloud.host) }}
  105. {{ else }}
  106. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEHOST" "value" (printf "%v:%v" .Values.nextcloud.host .Values.service.nodePort)) }}
  107. {{ end }}
  108. {{ end }}
  109. {{ $envList = mustAppend $envList (dict "name" "OVERWRITEPROTOCOL" "value" "https") }}
  110. {{ $envList = mustAppend $envList (dict "name" "TRUSTED_PROXIES" "value" "127.0.0.1") }}
  111. {{ end }}
  112. {{ $hostName := .Values.nextcloud.host }}
  113. {{ if .Values.useServiceNameForHost }}
  114. {{ $hostName = (include "common.names.fullname" .) }}
  115. {{ end }}
  116. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_TRUSTED_DOMAINS" "value" $hostName) }}
  117. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_USER" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-username") }}
  118. {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_PASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-password") }}
  119. {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }}
  120. ports:
  121. - name: http
  122. containerPort: 80
  123. protocol: TCP
  124. livenessProbe:
  125. httpGet:
  126. path: /status.php
  127. port: http
  128. httpHeaders:
  129. - name: Host
  130. value: localhost
  131. initialDelaySeconds: 10
  132. periodSeconds: 10
  133. timeoutSeconds: 5
  134. failureThreshold: 5
  135. successThreshold: 1
  136. readinessProbe:
  137. httpGet:
  138. path: /status.php
  139. port: http
  140. httpHeaders:
  141. - name: Host
  142. value: localhost
  143. initialDelaySeconds: 10
  144. periodSeconds: 10
  145. timeoutSeconds: 5
  146. failureThreshold: 5
  147. successThreshold: 1
  148. startupProbe:
  149. {{ $cmds := list }}
  150. {{ if .Values.nextcloud.install_ffmpeg }}
  151. {{ $cmds = mustAppend $cmds "ffmpeg" }}
  152. {{ end }}
  153. {{ if .Values.nextcloud.install_smbclient }}
  154. {{ $cmds = mustAppend $cmds "smbclient" }}
  155. {{ end }}
  156. {{ if $cmds }}
  157. exec:
  158. command:
  159. - /bin/sh
  160. - -c
  161. - |
  162. commands_to_check={{ join " " $cmds }}
  163. for comm in $commands_to_check; do
  164. if ! command -v $comm /dev/null 2>&1; then
  165. echo "Command $comm not found"
  166. exit 1
  167. fi
  168. done
  169. {{ else }}
  170. httpGet:
  171. path: /status.php
  172. port: http
  173. httpHeaders:
  174. - name: Host
  175. value: localhost
  176. {{ end }}
  177. initialDelaySeconds: 60
  178. periodSeconds: 10
  179. timeoutSeconds: 2
  180. failureThreshold: 100
  181. successThreshold: 1
  182. volumeMounts:
  183. - name: nextcloud-data
  184. mountPath: /var/www/
  185. subPath: "root"
  186. - name: nextcloud-data
  187. mountPath: /var/www/html
  188. subPath: "html"
  189. - name: nextcloud-data
  190. mountPath: {{ .Values.nextcloud.datadir }}
  191. subPath: "data"
  192. - name: nextcloud-data
  193. mountPath: /var/www/html/config
  194. subPath: "config"
  195. - name: nextcloud-data
  196. mountPath: /var/www/html/custom_apps
  197. subPath: "custom_apps"
  198. - name: nextcloud-data
  199. mountPath: /var/www/tmp
  200. subPath: "tmp"
  201. - name: nextcloud-data
  202. mountPath: /var/www/html/themes
  203. subPath: "themes"
  204. - name: nextcloud-configuration
  205. # We use -z-99 to ensure that this file is loaded
  206. # after the default opcache file nextcloud provides.
  207. mountPath: /usr/local/etc/php/conf.d/opcache-z-99.ini
  208. subPath: opcache.ini
  209. - name: nextcloud-configuration
  210. # We use -z-99 to ensure that this file is loaded
  211. # after the default php config file nextcloud provides.
  212. mountPath: /usr/local/etc/php/conf.d/nextcloud-z-99.ini
  213. subPath: php.ini
  214. - name: nextcloud-configuration
  215. # https://github.com/nextcloud/docker/issues/1796
  216. mountPath: /etc/apache2/conf-enabled/limitrequestbody.conf
  217. subPath: limitrequestbody.conf
  218. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  219. - name: extrappvolume-{{ $index }}
  220. mountPath: {{ $hostPathConfiguration.mountPath }}
  221. {{ end }}
  222. {{ if $cmds }}
  223. lifecycle:
  224. postStart:
  225. exec:
  226. command:
  227. - /bin/sh
  228. - -c
  229. - |
  230. echo "Installing {{ join " " $cmds }}..."
  231. apt update && \
  232. apt install -y --no-install-recommends \
  233. {{ join " " $cmds }} || echo "Failed to install binary/binaries"
  234. echo "Finished."
  235. {{ end }}
  236. {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }}
  237. volumes:
  238. - name: nextcloud-configuration
  239. configMap:
  240. defaultMode: 0755
  241. name: "nextcloud-configuration"
  242. - name: nginx-configuration
  243. configMap:
  244. defaultMode: 0700
  245. name: "nginx-configuration"
  246. {{ include "nginx.tlsKeysVolume" . | nindent 8 }}
  247. {{ if .Values.appVolumeMounts }}
  248. {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }}
  249. {{ end }}
  250. {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }}
  251. - name: extrappvolume-{{ $index }}
  252. hostPath:
  253. path: {{ $hostPathConfiguration.hostPath }}
  254. {{ end }}
  255. # Will mount configuration files as www-data (id: 33) for nextcloud
  256. securityContext:
  257. fsGroup: 33