From f4197b66816d79bb03b1c994f3488c7338204cbc Mon Sep 17 00:00:00 2001 From: dzhyranov Date: Sun, 16 Jun 2024 21:28:28 +0300 Subject: [PATCH 1/2] env --- .gitignore | 3 +- .infrastructure/deployment.yml | 60 +++++++++++++++++++--------------- README.md | 47 +++----------------------- src/todolist/settings.py | 2 +- 4 files changed, 41 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index 68bc17f..de5c021 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,5 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ + +.idea/ diff --git a/.infrastructure/deployment.yml b/.infrastructure/deployment.yml index 47f8efe..c67d18c 100644 --- a/.infrastructure/deployment.yml +++ b/.infrastructure/deployment.yml @@ -18,29 +18,37 @@ spec: app: todoapp spec: containers: - - name: todoapp - image: ikulyk404/todoapp:3.0.0 - resources: - requests: - memory: "256Mi" - cpu: "150m" - limits: - memory: "256Mi" - cpu: "150m" - env: - - name: PYTHONUNBUFFERED - value: "1" - ports: - - containerPort: 8080 - livenessProbe: - httpGet: - path: api/health - port: 8080 - initialDelaySeconds: 60 - periodSeconds: 5 - readinessProbe: - httpGet: - path: api/ready - port: 8080 - initialDelaySeconds: 5 - periodSeconds: 5 + - name: todoapp + image: ikulyk404/todoapp:3.0.0 + resources: + requests: + memory: "256Mi" + cpu: "150m" + limits: + memory: "256Mi" + cpu: "150m" + env: + - name: PYTHONUNBUFFERED + valueFrom: + configMapKeyRef: + name: todoapp-config + key: PYTHONUNBUFFERED + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: todoapp-secret + key: SECRET_KEY + ports: + - containerPort: 8080 + livenessProbe: + httpGet: + path: api/health + port: 8080 + initialDelaySeconds: 60 + periodSeconds: 5 + readinessProbe: + httpGet: + path: api/ready + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 5 diff --git a/README.md b/README.md index f4c4dfe..bea71d0 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,7 @@ -# Django ToDo list +## apply -This is a todo list web application with basic features of most web apps, i.e., accounts/login, API, and interactive UI. To do this task, you will need: +`kubectl apply -f .infrastructure/` -- CSS | [Skeleton](http://getskeleton.com/) -- JS | [jQuery](https://jquery.com/) +## check pods -## Explore - -Try it out by installing the requirements (the following commands work only with Python 3.8 and higher, due to Django 4): - -``` -pip install -r requirements.txt -``` - -Create a database schema: - -``` -python manage.py migrate -``` - -And then start the server (default is http://localhost:8000): - -``` -python manage.py runserver -``` - -Now you can browse the [API](http://localhost:8000/api/) or start on the [landing page](http://localhost:8000/). - -## Task - -Create a kubernetes manifest for a pod which will containa ToDo app container: - -1. Fork this repository. -1. Create a `confgiMap.yml` file for ConfigMap resource. -1. ConfigMap requirements: - 3.1. ConfigMap should have a `PYTHONUNBUFFERED` values set - 3.2. Deployment shoyld use this ConfigMap and set `PYTHONUNBUFFERED` environment variable -1. Create a `secret.yml` file for Secret resource. -1. Secret requirements: -5.1. Secret should have a `SECRET_KEY` value set -5.2. Deployment should use this Secret and set `SECRET_KEY` environment variable -5.3. Application should use this secret instead of one hardcoded in `settings.py` -1. `README.md` should have commands to apply all the changes -1. `README.md` should have instructuions on how to validate the changes -1. Create PR with your changes and attach it for validation on a platform. +`kubectl -n todoapp logs ` diff --git a/src/todolist/settings.py b/src/todolist/settings.py index e00a954..f46a432 100644 --- a/src/todolist/settings.py +++ b/src/todolist/settings.py @@ -18,7 +18,7 @@ # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "@e2(yx)v&tgh3_s=0yja-i!dpebxsz^dg47x)-k&kq_3zf*9e*" +SECRET_KEY = os.getenv('SECRET_KEY', default='SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True From 2dd234d0738f500bf3542ac70697709cf76ac8aa Mon Sep 17 00:00:00 2001 From: dzhyranov Date: Sun, 16 Jun 2024 21:28:33 +0300 Subject: [PATCH 2/2] add files; --- .infrastructure/configMap.yml | 7 +++++++ .infrastructure/secret.yml | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 .infrastructure/configMap.yml create mode 100644 .infrastructure/secret.yml diff --git a/.infrastructure/configMap.yml b/.infrastructure/configMap.yml new file mode 100644 index 0000000..7eecbcb --- /dev/null +++ b/.infrastructure/configMap.yml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: todoapp-config + namespace: todoapp +data: + PYTHONUNBUFFERED: "1" diff --git a/.infrastructure/secret.yml b/.infrastructure/secret.yml new file mode 100644 index 0000000..2ba8240 --- /dev/null +++ b/.infrastructure/secret.yml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: todoapp-secrets + namespace: todoapp +type: Opaque +data: + SECRET_KEY: "QGUyKHl4KXYmdGdoM19zPTB5amEtaSFkcGVieHN6XmRnNDd4KS1rJmtxXzN6Zio5ZSo="