api-deployment.yaml 5.38 KB
Newer Older
Markus Scheidgen's avatar
Markus Scheidgen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "nomad.fullname" . }}-api-gunicorn-log-config
  labels:
    app.kubernetes.io/name: {{ include "nomad.name" . }}-api-gunicorn-log-config
    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
58
59
60
61
62
63
64
65
66
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "nomad.fullname" . }}-api-gunicorn-config
  labels:
    app.kubernetes.io/name: {{ include "nomad.name" . }}-api-gunicorn-config
    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
    worker_class = '{{ .Values.api.workerClass }}'
68
    threads = {{ .Values.api.threads }}
69
    worker_connections = 1000
70
    worker = {{ .Values.api.worker }}
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
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "nomad.fullname" . }}-api
  labels:
    app.kubernetes.io/name: {{ include "nomad.name" . }}-api
    helm.sh/chart: {{ include "nomad.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.api.replicas }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "nomad.name" . }}-api
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "nomad.name" . }}-api
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
      - name: {{ include "nomad.name" . }}-api
        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
114
115
        - name: NOMAD_SERVICE
          value: "api"
        - name: NOMAD_CONSOLE_LOGLEVEL
116
          value: "{{ .Values.api.console_loglevel }}"
117
        - name: NOMAD_LOGSTASH_LEVEL
118
          value: "{{ .Values.api.logstash_loglevel }}"
119
120
121
122
123
124
125
        {{ if .Values.postgres.password_secret }}
        - name: NOMAD_REPOSITORY_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ .Values.postgres.password_secret }}
              key: password
        {{ end }}
126
127
        {{ if .Values.api.adminPasswordSecret }}
        - name: NOMAD_SERVICES_ADMIN_PASSWORD
128
          valueFrom:
129
130
131
132
            secretKeyRef:
              name: {{ .Values.api.adminPasswordSecret }}
              key: password
        {{ end }}
133
        command: ["python", "-m", "gunicorn.app.wsgiapp", "--config", "gunicorn.conf", "--log-config", "gunicorn.log.conf", "-b 0.0.0.0:8000", "nomad.app:app"]
134
135
        livenessProbe:
          httpGet:
136
            path: "{{ .Values.proxy.external.path }}/alive"
137
138
139
140
141
            port: 8000
          initialDelaySeconds: 15
          periodSeconds: 15
        readinessProbe:
          httpGet:
142
            path: "{{ .Values.proxy.external.path }}/alive"
143
144
145
            port: 8000
          initialDelaySeconds: 5
          periodSeconds: 5
146
      nodeSelector:
147
        nomadtype: {{ .Values.api.nomadNodeType }}
148
149
      imagePullSecrets:
      - name: {{ .Values.images.secret }}
150
      imagePullPolicy: always
151
      volumes:
Markus Scheidgen's avatar
Markus Scheidgen committed
152
153
154
      - name: gunicorn-log-conf
        configMap:
          name: {{ include "nomad.fullname" . }}-api-gunicorn-log-config
Markus Scheidgen's avatar
Markus Scheidgen committed
155
156
157
      - name: gunicorn-conf
        configMap:
          name: {{ include "nomad.fullname" . }}-api-gunicorn-config
158
159
160
      - name: nomad-conf
        configMap:
          name: {{ include "nomad.fullname" . }}-configmap
161
      - name: public-volume
162
        hostPath:
163
          path: {{ .Values.volumes.public }}
164
          type: Directory
165
      - name: staging-volume
166
        {{ if (eq .Values.worker.storage "memory") }}
167
168
169
170
        emptyDir:
          medium: 'Memory'
        {{ else }}
        hostPath:
171
          path: {{ .Values.volumes.staging}}
172
173
          type: Directory
        {{ end }}
174
175
176
177
      - name: nomad-volume
        hostPath:
          path: {{ .Values.volumes.nomad }}
          type: Directory