Skip to content

Commit

Permalink
Add nginx proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
frankh committed Jul 12, 2023
1 parent b317799 commit 16b8ed4
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 32 deletions.
55 changes: 55 additions & 0 deletions charts/housewatch/templates/deployment-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "housewatch.fullname" . }}-nginx
labels:
{{- include "housewatch.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "housewatch.selectorLabels" . | nindent 6 }}
app.kubernetes.io/service: nginx
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "housewatch.selectorLabels" . | nindent 8 }}
app.kubernetes.io/service: nginx
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: frontend
emptyDir: {}
- name: nginx-config
configMap:
name: {{ include "housewatch.fullname" . }}-nginx
initContainers:
- name: frontend-copy
image: "{{ .Values.image.frontendRepository }}:{{ .Values.image.tag }}"
command: [sh, -cex]
args:
- cp -r /frontend/build/* /http/
volumeMounts:
- mountPath: /http
name: frontend
containers:
- name: nginx
image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag }}"
ports:
- name: http
containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /http
name: frontend
- mountPath: /etc/nginx/nginx.conf
name: nginx-config
subPath: nginx.conf
resources:
{{- toYaml .Values.nginx.resources | nindent 12 }}
35 changes: 4 additions & 31 deletions charts/housewatch/templates/deployment-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: frontend
image: "{{ .Values.image.frontendRepository }}:{{ .Values.image.tag }}"
# would be nice to figure out a way other than react dev server but ¯\_(ツ)_/¯
command: ["npm", "run", "start"]
ports:
- name: frontend
containerPort: 3000
protocol: TCP
env:
- name: DANGEROUSLY_DISABLE_HOST_CHECK
value: "true"
livenessProbe:
httpGet:
path: /
port: frontend
readinessProbe:
httpGet:
path: /
port: frontend
startupProbe:
httpGet:
path: /
port: frontend
failureThreshold: 60
periodSeconds: 10
resources:
{{- toYaml .Values.frontend.resources | nindent 12 }}
- name: web
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["bash", "-c"]
Expand All @@ -59,7 +32,7 @@ spec:
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
ports:
- name: http
- name: api
containerPort: 8000
protocol: TCP
env:
Expand All @@ -72,7 +45,7 @@ spec:
- name: CLICKHOUSE_USER
value: "{{ .Values.clickhouse.user }}"
- name: CLICKHOUSE_PASSWORD
value: "" # todo: secret
value: "{{ .Values.clickhouse.password }}"
- name: CLICKHOUSE_CLUSTER
value: {{ .Values.clickhouse.cluster }}
- name: CLICKHOUSE_SECURE
Expand All @@ -84,10 +57,10 @@ spec:
livenessProbe:
httpGet:
path: /
port: http
port: api
readinessProbe:
httpGet:
path: /
port: http
port: api
resources:
{{- toYaml .Values.web.resources | nindent 12 }}
33 changes: 33 additions & 0 deletions charts/housewatch/templates/nginx-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "housewatch.fullname" . }}-nginx
data:
nginx.conf: |
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
location / {
root /http;
try_files $uri $uri/ =404;
}
location /api {
proxy_pass http://{{ include "housewatch.fullname" . }}-api:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
}
}
}
19 changes: 18 additions & 1 deletion charts/housewatch/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,26 @@ spec:
type: ClusterIP
ports:
- port: 80
targetPort: frontend
targetPort: http
protocol: TCP
name: http
selector:
{{- include "housewatch.selectorLabels" . | nindent 4 }}
app.kubernetes.io/service: nginx
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "housewatch.fullname" . }}-api
labels:
{{- include "housewatch.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: 8000
targetPort: api
protocol: TCP
name: api
selector:
{{- include "housewatch.selectorLabels" . | nindent 4 }}
app.kubernetes.io/service: web
Expand Down
5 changes: 5 additions & 0 deletions charts/housewatch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ image:
frontendRepository: ghcr.io/posthog/housewatch/frontend
tag: sha-4cbdf5e

nginx:
image:
repository: nginx
tag: stable

clickhouse:
user: default
host: clickhouse
Expand Down

0 comments on commit 16b8ed4

Please sign in to comment.