-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.yml
More file actions
188 lines (187 loc) · 4.26 KB
/
Copy pathdeployment.yml
File metadata and controls
188 lines (187 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: http-01-production
spec:
acme:
email: your-email@devopsbyexample.com
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: http-01-production-cluster-issuer # secrets get created in cert-manager-namespace
solvers:
- http01: # two types of challenges, http-01 and dns-01. dns-01 needs a dns record to be created
ingress:
ingressClassName: external-nginx
---
apiVersion: v1
kind: Namespace
metadata:
name: webapp
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-app
namespace: webapp
spec:
replicas: 1
selector:
matchLabels:
app: django-app
template:
metadata:
labels:
app: django-app
spec:
containers:
- name: django-app
image: prabhjotbawa/mywebapp:latest
ports:
- containerPort: 5001
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: DJANGO_DISABLE_MIGRATIONS
value: 'false' # Run migration
- name: DB_NAME
value: mydatabase
- name: DB_USER
valueFrom:
secretKeyRef:
name: postgres-secrets
key: postgres-user
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secrets
key: postgres-password
- name: DB_HOST
value: postgres-service
- name: DB_PORT
value: "5432"
- name: ALLOWED_HOSTS
value: testapp.prabhjotbawa.com
- name: CSRF_TRUSTED_ORIGINS
value: https://testapp.prabhjotbawa.com
---
apiVersion: v1
kind: Service
metadata:
name: django-app-service
namespace: webapp
spec:
selector:
app: django-app
ports:
- protocol: TCP
port: 5001
targetPort: 5001
type: ClusterIP # Changed from LoadBalancer to ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: django-app-ingress
namespace: webapp
annotations:
cert-manager.io/cluster-issuer: http-01-production # points to the cluster issuer
spec:
ingressClassName: external-nginx
rules:
- host: testapp.prabhjotbawa.com # Create a CNAME DNS record in Route 53 to point to the LB
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: django-app-service
port:
number: 5001
tls:
- hosts:
- testapp.prabhjotbawa.com
secretName: testapp-prabhjotbawa-com
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: webapp
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: mydatabase
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secrets
key: postgres-user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secrets
key: postgres-password
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-storage
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: postgres-service
namespace: webapp
spec:
selector:
app: postgres
ports:
- protocol: TCP
port: 5432
targetPort: 5432
---
apiVersion: v1
kind: Secret
metadata:
name: postgres-secrets
namespace: webapp
type: Opaque
data:
postgres-user: bXl1c2Vy # base64 encoded "myuser"
postgres-password: bXlwYXNzd29yZA== # base64 encoded "mypassword"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-init-script
namespace: webapp
data:
init.sh: |
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE TABLE IF NOT EXISTS myapp_mymodel (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT
);
EOSQL