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