api-deployment.yaml 6.14 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
    [formatters]
Markus Scheidgen's avatar
Markus Scheidgen committed
19
    keys=generic, json
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
    [handler_access]
Markus Scheidgen's avatar
Markus Scheidgen committed
41
    class=StreamHandler
Markus Scheidgen's avatar
Markus Scheidgen committed
42
    formatter=json
Markus Scheidgen's avatar
Markus Scheidgen committed
43
    args=(sys.stdout, )
Markus Scheidgen's avatar
Markus Scheidgen committed
44

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

Markus Scheidgen's avatar
Markus Scheidgen committed
50
51
52
53
    [formatter_generic]
    format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
    datefmt=%Y-%m-%d %H:%M:%S
    class=logging.Formatter
Markus Scheidgen's avatar
Markus Scheidgen committed
54
55
56

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