-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeployment.yaml
175 lines (175 loc) · 6.38 KB
/
deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{{- if .Values.appEnabled -}}
{{- $fullName := include "generic-govuk-app.fullname" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullName }}
labels:
{{- include "generic-govuk-app.labels" . | nindent 4 }}
app: {{ $fullName }}
app.kubernetes.io/name: {{ $fullName }}
app.kubernetes.io/component: app
spec:
replicas: {{ .Values.replicaCount }}
revisionHistoryLimit: 2
selector:
matchLabels:
app: {{ $fullName }}
template:
metadata:
labels:
{{- include "generic-govuk-app.labels" . | nindent 8 }}
app: {{ $fullName }}
app.kubernetes.io/name: {{ $fullName }}
app.kubernetes.io/component: app
spec:
automountServiceAccountToken: false
enableServiceLinks: false
securityContext:
fsGroup: {{ .Values.securityContext.runAsGroup }}
runAsNonRoot: {{ .Values.securityContext.runAsNonRoot }}
runAsUser: {{ .Values.securityContext.runAsUser }}
runAsGroup: {{ .Values.securityContext.runAsGroup }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{- . | toYaml | trim | nindent 8 }}
{{- end }}
volumes:
- name: {{ .Values.nginxConfigMap.name | default (printf "%s-nginx-conf" $fullName) }}
configMap:
name: {{ .Values.nginxConfigMap.name | default (printf "%s-nginx-conf" $fullName) }}
- name: app-tmp
emptyDir: {}
- name: nginx-tmp
emptyDir: {}
{{- if .Values.serveRailsAssetsFromFilesystem }}
- name: assets
emptyDir: {}
{{- end }}
{{- with .Values.extraVolumes }}
{{- . | toYaml | trim | nindent 8 }}
{{- end }}
{{- if .Values.serveRailsAssetsFromFilesystem }}
initContainers:
- name: copy-assets
image: "{{ .Values.appImage.repository }}:{{ .Values.appImage.tag }}"
imagePullPolicy: {{ .Values.appImage.pullPolicy | default "Always" }}
{{- $sourcePath := .Values.uploadAssets.path | default (printf "/app/public/assets/%s" .Values.repoName) }}
command: ["cp", "-R", "{{ $sourcePath }}", "/assets"]
volumeMounts:
- name: assets
mountPath: /assets
{{- end }}
containers:
- name: app
image: "{{ .Values.appImage.repository }}:{{ .Values.appImage.tag }}"
imagePullPolicy: {{ .Values.appImage.pullPolicy | default "Always" }}
ports:
- name: http
containerPort: {{ .Values.appPort }}
- name: metrics
containerPort: {{ .Values.metricsPort }}
envFrom:
- configMapRef:
name: govuk-apps-env
env:
- name: PORT
value: "{{ .Values.appPort }}"
{{- if .Values.rails.enabled }}
- name: SECRET_KEY_BASE
valueFrom:
secretKeyRef:
name: {{ .Values.rails.secretKeyBaseName | default (printf "%s-rails-secret-key-base" .Values.repoName) }}
key: secret-key-base
{{- end }}
{{- if .Values.sentry.enabled }}
- name: SENTRY_DSN
valueFrom:
secretKeyRef:
name: {{ .Values.sentry.dsnSecretName | default (printf "%s-sentry" .Values.repoName) }}
key: dsn
- name: SENTRY_RELEASE
value: "{{ .Values.appImage.tag }}"
{{- end }}
{{- with .Values.extraEnv }}
{{- (tpl (toYaml .) $) | trim | nindent 12 }}
{{- end }}
{{- with .Values.appResources }}
resources:
{{- . | toYaml | trim | nindent 12 }}
{{- end }}
{{- with .Values.appProbes }}
{{- . | toYaml | trim | nindent 10 }}
{{- else }}
livenessProbe: &app-probe
httpGet:
path: /healthcheck/live
port: http
failureThreshold: 3
periodSeconds: 5
timeoutSeconds: 30
readinessProbe:
<<: *app-probe # Intentionally same path as liveness.
failureThreshold: 2
startupProbe:
<<: *app-probe
failureThreshold: 15
periodSeconds: 2
timeoutSeconds: 2
{{- end }}
securityContext:
allowPrivilegeEscalation: {{ .Values.securityContext.allowPrivilegeEscalation }}
readOnlyRootFilesystem: true
volumeMounts:
- name: app-tmp
mountPath: /tmp
{{- with .Values.appExtraVolumeMounts }}
{{- . | toYaml | trim | nindent 12 }}
{{- end }}
lifecycle:
preStop:
exec:
command: ["sleep", "15"] # To allow time for ALB to deregister pod before termination
- name: nginx
image: "{{ .Values.nginxImage.repository }}:{{ .Values.nginxImage.tag }}"
imagePullPolicy: {{ .Values.nginxImage.pullPolicy | default "Always" }}
ports:
- name: http
containerPort: {{ .Values.nginxPort }}
livenessProbe: &nginx-probe
httpGet:
path: /readyz
port: http
initialDelaySeconds: 2
failureThreshold: 3
periodSeconds: 5
timeoutSeconds: 20
readinessProbe:
<<: *nginx-probe # Intentionally same path as liveness.
failureThreshold: 2
timeoutSeconds: 15
{{- with .Values.nginxResources }}
resources:
{{- . | toYaml | trim | nindent 12 }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
volumeMounts:
- name: {{ .Values.nginxConfigMap.name | default (printf "%s-nginx-conf" $fullName) }}
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-tmp
mountPath: /tmp
{{- if .Values.serveRailsAssetsFromFilesystem }}
- name: assets
mountPath: /assets
{{- end }}
{{- with .Values.nginxExtraVolumeMounts }}
{{ . | toYaml | trim | nindent 12 }}
{{- end }}
lifecycle:
preStop:
exec:
command: ["sleep", "15"] # To allow time for ALB to deregister pod before termination
{{- end }}