api-deployment.yaml 6.07 KB
Newer Older
Markus Scheidgen's avatar
Markus Scheidgen committed
1
2
3
apiVersion: v1
kind: ConfigMap
metadata:
4
  name: {{ include "nomad.fullname" . }}-app-gunicorn-log-config
Markus Scheidgen's avatar
Markus Scheidgen committed
5
  labels:
6
    app.kubernetes.io/name: {{ include "nomad.name" . }}-app-gunicorn-log-config
Markus Scheidgen's avatar
Markus Scheidgen committed
7
8
9
10
11
12
13
    helm.sh/chart: {{ include "nomad.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
  gunicorn.log.conf: |
    [loggers]
    keys=root, gunicorn.error, gunicorn.access
Markus Scheidgen's avatar
Markus Scheidgen committed
14

Markus Scheidgen's avatar
Markus Scheidgen committed
15
16
    [handlers]
    keys=console, access, error
Markus Scheidgen's avatar
Markus Scheidgen committed
17

Markus Scheidgen's avatar
Markus Scheidgen committed
18
19
    [formatters]
    keys=generic
Markus Scheidgen's avatar
Markus Scheidgen committed
20

Markus Scheidgen's avatar
Markus Scheidgen committed
21
22
23
    [logger_root]
    level=INFO
    handlers=console
Markus Scheidgen's avatar
Markus Scheidgen committed
24

Markus Scheidgen's avatar
Markus Scheidgen committed
25
26
27
28
    [logger_gunicorn.error]
    level=INFO
    handlers=error
    qualname=gunicorn.error
Markus Scheidgen's avatar
Markus Scheidgen committed
29

Markus Scheidgen's avatar
Markus Scheidgen committed
30
31
32
33
    [logger_gunicorn.access]
    level=INFO
    handlers=access
    qualname=gunicorn.access
Markus Scheidgen's avatar
Markus Scheidgen committed
34

Markus Scheidgen's avatar
Markus Scheidgen committed
35
36
37
38
    [handler_console]
    class=StreamHandler
    formatter=generic
    args=(sys.stdout, )
Markus Scheidgen's avatar
Markus Scheidgen committed
39

Markus Scheidgen's avatar
Markus Scheidgen committed
40
41
42
43
    [handler_access]
    class=StreamHandler
    formatter=generic
    args=(sys.stdout, )
Markus Scheidgen's avatar
Markus Scheidgen committed
44

Markus Scheidgen's avatar
Markus Scheidgen committed
45
46
47
48
    [handler_error]
    class=StreamHandler
    formatter=generic
    args=(sys.stdout, )
Markus Scheidgen's avatar
Markus Scheidgen committed
49

Markus Scheidgen's avatar
Markus Scheidgen committed
50
51
52
53
54
    [formatter_generic]
    format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
    datefmt=%Y-%m-%d %H:%M:%S
    class=logging.Formatter
---
55
56
57
apiVersion: v1
kind: ConfigMap
metadata:
58
  name: {{ include "nomad.fullname" . }}-app-gunicorn-config
59
  labels:
60
    app.kubernetes.io/name: {{ include "nomad.name" . }}-app-gunicorn-config
61
62
63
64
65
66
    helm.sh/chart: {{ include "nomad.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
  gunicorn.conf: |
    secure_scheme_headers = {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
67
    {{ if ne .Values.app.workerClass "sync" }}
Markus Scheidgen's avatar
Markus Scheidgen committed
68
69
    worker_class = '{{ .Values.app.workerClass }}'
    threads = {{ .Values.app.threads }}
70
    {{ end }}
71
    worker_connections = 1000
72
    workers = {{ .Values.app.worker }}
73
---
74
75
76
apiVersion: apps/v1
kind: Deployment
metadata:
77
  name: {{ include "nomad.fullname" . }}-app
78
  labels:
79
    app.kubernetes.io/name: {{ include "nomad.name" . }}-app
80
81
82
83
    helm.sh/chart: {{ include "nomad.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
84
  replicas: {{ .Values.app.replicas }}
85
86
  selector:
    matchLabels:
87
      app.kubernetes.io/name: {{ include "nomad.name" . }}-app
88
89
90
91
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
92
        app.kubernetes.io/name: {{ include "nomad.name" . }}-app
93
94
95
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
96
      - name: {{ include "nomad.name" . }}-app
97
98
        image: "{{ .Values.images.nomad.name }}:{{ .Values.images.nomad.tag }}"
        volumeMounts:
Markus Scheidgen's avatar
Markus Scheidgen committed
99
        - mountPath: /app/nomad.yaml
100
          name: nomad-conf
Markus Scheidgen's avatar
Markus Scheidgen committed
101
102
103
104
          subPath: nomad.yaml
        - mountPath: /app/gunicorn.log.conf
          name: gunicorn-log-conf
          subPath: gunicorn.log.conf
Markus Scheidgen's avatar
Markus Scheidgen committed
105
106
107
        - mountPath: /app/gunicorn.conf
          name: gunicorn-conf
          subPath: gunicorn.conf
108
        - mountPath: /app/.volumes/fs/public
109
110
111
          name: public-volume
        - mountPath: /app/.volumes/fs/staging
          name: staging-volume
112
113
        - mountPath: /nomad
          name: nomad-volume
Markus Scheidgen's avatar
Markus Scheidgen committed
114
        env:
115
        - name: NOMAD_SERVICE
116
          value: "app"
117
        - name: NOMAD_CONSOLE_LOGLEVEL
118
          value: "{{ .Values.app.console_loglevel }}"
119
        - name: NOMAD_LOGSTASH_LEVEL
120
          value: "{{ .Values.app.logstash_loglevel }}"
121
       {{ if .Values.api.apiSecret }}
122
        - name: NOMAD_SERVICES_API_SECRET
123
          valueFrom:
124
            secretKeyRef:
125
              name: {{ .Values.api.apiSecret}}
126
127
              key: password
        {{ end }}
128
129
        {{ if .Values.keycloak.clientSecret }}
        - name: NOMAD_KEYCLOAK_CLIENT_SECRET
130
          valueFrom:
131
            secretKeyRef:
132
              name: {{ .Values.keycloak.clientSecret }}
133
134
              key: password
        {{ end }}
135
136
        {{ if .Values.keycloak.passwordSecret }}
        - name: NOMAD_KEYCLOAK_PASSWORD
137
          valueFrom:
138
139
140
141
            secretKeyRef:
              name: {{ .Values.keycloak.passwordSecret }}
              key: password
        {{ end }}
Markus Scheidgen's avatar
Markus Scheidgen committed
142
143
144
145
146
147
148
149
150
151
152
153
        {{ if .Values.datacite.secret }}
        - name: NOMAD_DATACITE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ .Values.datacite.secret }}
              key: password
        - name: NOMAD_DATACITE_USER
          valueFrom:
            secretKeyRef:
              name: {{ .Values.datacite.secret }}
              key: user
        {{ end }}
154
        command: ["python", "-m", "gunicorn.app.wsgiapp", "--config", "gunicorn.conf", "--log-config", "gunicorn.log.conf", "-b 0.0.0.0:8000", "nomad.app:app"]
155
156
        livenessProbe:
          httpGet:
157
            path: "{{ .Values.proxy.external.path }}/alive"
158
            port: 8000
159
160
161
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5
162
163
        readinessProbe:
          httpGet:
164
            path: "{{ .Values.proxy.external.path }}/alive"
165
            port: 8000
166
167
168
          initialDelaySeconds: 15
          periodSeconds: 15
          timeoutSeconds: 5
169
      nodeSelector:
170
        nomadtype: {{ .Values.app.nomadNodeType }}
171
172
      imagePullSecrets:
      - name: {{ .Values.images.secret }}
173
      imagePullPolicy: always
174
      volumes:
Markus Scheidgen's avatar
Markus Scheidgen committed
175
176
      - name: gunicorn-log-conf
        configMap:
177
          name: {{ include "nomad.fullname" . }}-app-gunicorn-log-config
Markus Scheidgen's avatar
Markus Scheidgen committed
178
179
      - name: gunicorn-conf
        configMap:
180
          name: {{ include "nomad.fullname" . }}-app-gunicorn-config
181
182
183
      - name: nomad-conf
        configMap:
          name: {{ include "nomad.fullname" . }}-configmap
184
      - name: public-volume
185
        hostPath:
186
          path: {{ .Values.volumes.public }}
187
          type: Directory
188
      - name: staging-volume
189
        {{ if (eq .Values.worker.storage "memory") }}
190
191
192
193
        emptyDir:
          medium: 'Memory'
        {{ else }}
        hostPath:
194
          path: {{ .Values.volumes.staging}}
195
196
          type: Directory
        {{ end }}
197
198
199
200
      - name: nomad-volume
        hostPath:
          path: {{ .Values.volumes.nomad }}
          type: Directory