Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 78ddaa7

Browse files
committed
fixed minikube settings, added migration job
1 parent 178312d commit 78ddaa7

File tree

12 files changed

+128
-65
lines changed

12 files changed

+128
-65
lines changed

backend/backend/settings/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
SECRET_KEY = os.environ.get('SECRET_KEY', '')
2828

2929
# SECURITY WARNING: don't run with debug turned on in production!
30-
DEBUG = bool(os.environ.get('DEBUG', False))
30+
DEBUG = bool(os.environ.get('DEBUG', True))
3131

3232
ALLOWED_HOSTS = ['*']
3333

backend/backend/settings/minikube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'NAME': os.environ.get('POSTGRES_NAME', 'kubernetes_django'), # noqa
99
'USER': os.environ.get('POSTGRES_USER', 'postgres'), # noqa
1010
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'), # noqa
11-
'HOST': os.environ.get('POSTGRES_HOST', 'postgres'), # noqa
12-
'PORT': os.environ.get('POSTGRES_PORT', 5432), # noqa
11+
'HOST': os.environ.get('POSTGRES_SERVICE_HOST', 'postgres'), # noqa
12+
'PORT': os.environ.get('POSTGRES_SERVICE_PORT', 5432), # noqa
1313
}
1414
}

compose/minikube.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.7'
2+
3+
services:
4+
5+
frontend:
6+
image: frontend:1
7+
build:
8+
context: ../
9+
dockerfile: nginx/minikube/Dockerfile
10+
args:
11+
- DOMAIN_NAME=test.dev
12+
- GOOGLE_OAUTH2_KEY=google123
13+
- GITHUB_KEY=github123
14+
- WS_PROTOCOL=ws
15+
- HTTP_PROTOCOL=http
16+
17+
backend:
18+
image: backend:2
19+
build:
20+
context: ../backend/
21+
dockerfile: scripts/dev/Dockerfile
22+

documentation/docs/topics/minikube/README.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ Running migrations:
231231
Try this again with a clean version of minikube and using the Secrets resource.
232232
:::
233233
234+
## Secrets
235+
236+
Let's use base64 encoding to define a username and password for our Postgres username and password:
237+
238+
```
239+
echo -n "my-string" | base64
240+
```
241+
234242
I initially started the postgres container with a password set by environment variable. This may have set data in the
235243
236244
::: tip kubectl cheatsheet from kubernetes documentation
@@ -272,30 +280,33 @@ This works from inside of a pod, but we can't use this for our static site since
272280
273281
**minikube/Dockerfile**
274282
275-
```Dockerfile
276-
# build stage
277-
FROM node:10-alpine as build-stage
278-
WORKDIR /app/
279-
ENV DOMAIN_NAME 192.168.99.101:30958 <-- this is the nodePort for the backend service
280-
ENV HTTP_PROTOCOL http
281-
COPY quasar/package.json /app/
282-
RUN npm cache verify
283-
RUN npm install -g @quasar/cli
284-
RUN npm install --progress=false
285-
COPY quasar /app/
286-
RUN quasar build -m pwa
287-
288-
# minikube stage
289-
FROM nginx:1.13.12-alpine as minikube
290-
COPY nginx/minikube/minikube.conf /etc/nginx/nginx.conf
291-
COPY --from=build-stage /app/dist/pwa /dist/
292-
EXPOSE 80
293-
CMD ["nginx", "-g", "daemon off;"]
283+
Use the following command to build the frontend resources in minikube:
284+
294285
```
286+
docker-compose -f compose/minikube.yml build frontend
287+
```
288+
289+
Make sure that your current shell has the correct environment variables set for the `DOCKER_HOST` by running:
290+
291+
```
292+
eval $(minikube docker-env)
293+
```
294+
295+
296+
297+
We can pass the environment variables needed during the build process with `ARG` and `ENV`.
298+
299+
For `DOMAIN_NAME`, want to use an address that will point to the minikube Kubernetes cluster. Since the IP might change, we can set this to a named domain such as `test.dev`, and add a line to `/etc/hosts` that will point `test.dev` to the minikube IP. Then, we will need to setup a ingress to point `test.dev` to our `kubernetes-django-service` service.
295300
296-
We need to set the `DOMAIN_NAME` environment variable to `kubernetes-django-service`, and also set the port, and we should be able to access the backend from frontend AJAX calls.
297301
298302
## Troubleshooting and Misc
299303
300304
https://stackoverflow.com/questions/55573426/virtualbox-is-configured-with-multiple-host-only-adapters-with-the-same-ip-whe
301305
306+
307+
308+
## Enable Ingress Addon in Minikibe
309+
310+
```
311+
minikube addons enable ingress
312+
```

kubernetes/django/deployment.yml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
containers:
1616
- name: backend
1717
imagePullPolicy: IfNotPresent
18-
image: backend:12
18+
image: backend:2
1919
command: ["./manage.py", "runserver", "0.0.0.0:8000"]
2020
ports:
2121
- containerPort: 8000
@@ -26,25 +26,20 @@ spec:
2626
- name: SECRET_KEY
2727
value: "my-secret-key"
2828

29-
- name: POSTGRES_USER
30-
value: postgres
31-
# valueFrom:
32-
# secretKeyRef:
33-
# name: postgres-credentials
34-
# key: user
35-
36-
- name: POSTGRES_PASSWORD
29+
- name: POSTGRES_NAME
3730
value: postgres
38-
# valueFrom:
39-
# secretKeyRef:
40-
# name: postgres-credentials
41-
# key: password
4231

43-
- name: DEBUG
44-
value: "True"
32+
- name: POSTGRES_USER
33+
valueFrom:
34+
secretKeyRef:
35+
name: postgres-credentials
36+
key: user
4537

46-
- name: POSTGRES_HOST
47-
value: postgres-service
38+
- name: POSTGRES_PASSWORD
39+
valueFrom:
40+
secretKeyRef:
41+
name: postgres-credentials
42+
key: password
4843

4944
volumeMounts:
5045
- name: postgres-volume-mount

kubernetes/django/migration.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: django-migrations
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: django
10+
image: backend:2
11+
command: ['python', 'manage.py', 'migrate']
12+
env:
13+
- name: POSTGRES_USER
14+
valueFrom:
15+
secretKeyRef:
16+
name: postgres-credentials
17+
key: user
18+
19+
- name: POSTGRES_PASSWORD
20+
valueFrom:
21+
secretKeyRef:
22+
name: postgres-credentials
23+
key: password
24+
25+
- name: POSTGRES_NAME
26+
value: postgres
27+
28+
- name: DJANGO_SETTINGS_MODULE
29+
value: 'backend.settings.minikube'
30+
31+
restartPolicy: Never
32+
backoffLimit: 5

kubernetes/frontend/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ spec:
1717
containers:
1818
- name: frontend
1919
imagePullPolicy: IfNotPresent
20-
image: frontend:one
20+
image: frontend:1

kubernetes/frontend/service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
selector:
77
app: frontend-container
88
ports:
9-
- nodePort: 30001
9+
- nodePort: 30002
1010
protocol: TCP
1111
port: 80
1212
targetPort: 80

kubernetes/postgres/deployment.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ spec:
1818
image: postgres:9.6.6
1919
env:
2020
- name: POSTGRES_USER
21-
value: postgres
22-
# valueFrom:
23-
# secretKeyRef:
24-
# name: postgres-credentials
25-
# key: user
21+
valueFrom:
22+
secretKeyRef:
23+
name: postgres-credentials
24+
key: user
2625

2726
- name: POSTGRES_PASSWORD
28-
value: postgres
29-
# valueFrom:
30-
# secretKeyRef:
31-
# name: postgres-credentials
32-
# key: password
33-
34-
- name: POSTGRES_NAME
35-
value: kubernetes_django
27+
valueFrom:
28+
secretKeyRef:
29+
name: postgres-credentials
30+
key: password
3631

3732
ports:
3833
- containerPort: 5432
@@ -43,4 +38,4 @@ spec:
4338
volumes:
4439
- name: postgres-volume-mount
4540
persistentVolumeClaim:
46-
claimName: postgres-pvc
41+
claimName: postgres-pvc

kubernetes/postgres/secrets.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ metadata:
44
name: postgres-credentials
55
type: Opaque
66
data:
7-
user: postgres
8-
password: postgres
7+
user: YnJpYW4=
8+
password: cGFzc3dvcmQx

0 commit comments

Comments
 (0)