Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .infrastructure/configMap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: todoapp-config
namespace: todoapp
data:
PYTHONUNBUFFERED: "1"
10 changes: 9 additions & 1 deletion .infrastructure/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ spec:
cpu: "150m"
env:
- name: PYTHONUNBUFFERED
value: "1"
valueFrom:
configMapKeyRef:
name: todoapp-config
key: PYTHONUNBUFFERED
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: todoapp-secret
key: SECRET_KEY
ports:
- containerPort: 8080
livenessProbe:
Expand Down
8 changes: 8 additions & 0 deletions .infrastructure/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: todoapp-secret
namespace: todoapp
type: Opaque
data:
SECRET_KEY: "TXlTZWNyZXRLZXk="
53 changes: 17 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
# Django ToDo list
# Implementing secret and configMap into TodoApp

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:
## 1. Apply updated manifests:
```bash
kubectl apply -f ./.infrascructure/configMap.yml

- CSS | [Skeleton](http://getskeleton.com/)
- JS | [jQuery](https://jquery.com/)

## Explore

Try it out by installing the requirements (the following commands work only with Python 3.8 and higher, due to Django 4):
kubectl apply -f ./.infrascructure/secret.yml

```
pip install -r requirements.txt
kubectl apply -f ./.infrascructure/deployment.yml
```

Create a database schema:
## 2. Check the status of the pods and pod info:
```bash
kubectl get pods -n todoapp

```
python manage.py migrate
kubectl get secrets -n todoapp

kubectl get configmap -n todoapp
```

And then start the server (default is http://localhost:8000):
### 3. Check new environment and secret values:

```
python manage.py runserver
```
```bash
kubectl exec -it <pod-name> -n todoapp -- printenv | grep PYTHONUNBUFFERED

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 exec -it <pod-name> -n todoapp -- printenv | grep SECRET_KEY
```
2 changes: 1 addition & 1 deletion src/todolist/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down