Skip to content

Commit e661c62

Browse files
Merge pull request #13 from aleyipsoftwire/exercise-14
Exercise 14
2 parents 5482bba + 4f6ce48 commit e661c62

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,20 @@ See https://learn.microsoft.com/en-us/azure/cosmos-db/database-encryption-at-res
187187
Minimum level of shown logs can be configured by the `LOG_LEVEL` env var.
188188

189189
Populate the `LOGGLY_TOKEN` env var for logs to be sent to Loggly.
190+
191+
## Running in k8s
192+
193+
1. Install `kubectl` and `minikube`
194+
2. Build a prod image: `docker build --target production --tag todo-app:prod .`
195+
3. Load the image into minikube: `minikube image load todo-app:prod`
196+
4. Create the secret for env variables:
197+
```shell
198+
kubectl create secret generic container-env \
199+
--from-literal=FLASK_APP='todo_app/app' \
200+
--from-literal=MONGODB_PRIMARY_CONNECTION_STRING='<DELIBERATELY MISSING>' \
201+
--from-literal=LOGGLY_TOKEN='<DELIBERATELY MISSING>' \
202+
--from-literal=LOG_LEVEL='DEBUG'
203+
```
204+
5. Apply the k8s YAML files: `kubectl apply -f deployment.yaml -f service.yaml`
205+
6. Expose the port: `kubectl port-forward service/module-14 7080:80`
206+
7. Open http://localhost:7080 to view the app

deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: module-14
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: module-14
9+
replicas: 1
10+
template:
11+
metadata:
12+
labels:
13+
app: module-14
14+
spec:
15+
containers:
16+
- name: "todo-app"
17+
image: "todo-app:prod"
18+
ports:
19+
- containerPort: 8000
20+
imagePullPolicy: "Never"
21+
envFrom:
22+
- secretRef:
23+
name: container-env

service.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: module-14
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: module-14
9+
ports:
10+
- protocol: TCP
11+
port: 80
12+
targetPort: 8000

0 commit comments

Comments
 (0)