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

manifests for k8s todolist #41

Open
wants to merge 3 commits 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
12 changes: 12 additions & 0 deletions .infrastructure/busybox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: todoapp
spec:
containers:
- name: busybox
image: ikulyk404/busyboxplus:curl
args:
- sleep
- "1000"
4 changes: 4 additions & 0 deletions .infrastructure/namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: todoapp
23 changes: 23 additions & 0 deletions .infrastructure/todoapp-pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Pod
metadata:
name: todoapp
namespace: todoapp
spec:
containers:
- name: todoapp
image: nmakivchuk01/todoapp:3.0.0
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: api/liveness
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: api/readiness
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG PYTHON_VERSION=3.8

FROM python:${PYTHON_VERSION}

WORKDIR /app

COPY ./src .

RUN pip install --upgrade pip && \
pip install -r requirements.txt

EXPOSE 8080

ENTRYPOINT ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8080"]
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,30 @@ metadata:
1. `README.md` file should contain instructions on how to test application using the
`busyboxplus:curl` container
1. Create PR with your changes and attach it for validation on a platform.

# Instructions on how to apply all manifests
```
kubectl apply -f ./.infrastructure/namespace.yml

kubectl apply -f ./.infrastructure/todoapp-pod.yml

kubectl apply -f ./.infrastructure/busybox.yml
```

# Instructions on how to test ToDo application
```
kubectl port-forward pod/todoapp 8080:8080 -n todoapp
```
# Instructions on how to test application
1. To get the IP address of Todo App:
```
kubectl get pods -n todoapp -o wide
```
2. To get access to busybox shell:
```
kubectl -n todoapp exec -it busybox -- sh
```
3. To send curl request:
```
curl [TodoApp_IP]:8080
```
4 changes: 3 additions & 1 deletion src/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

app_name = "api"
urlpatterns = [
path("", include(router.urls))
path("", include(router.urls)),
path("readiness/", views.readiness, name="readiness"),
path("liveness/", views.liveness, name="liveness")
]
15 changes: 14 additions & 1 deletion src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from django.utils import timezone
import time

startTime = time.time()
delayTime = 40


class IsCreatorOrReadOnly(permissions.BasePermission):
"""
Object-level permission to only allow owners of an object to edit it.
Expand Down Expand Up @@ -55,4 +59,13 @@ class TodoViewSet(viewsets.ModelViewSet):
def perform_create(self, serializer):
user = self.request.user
creator = user if user.is_authenticated else None
serializer.save(creator=creator)
serializer.save(creator=creator)

def liveness(request):
return HttpResponse("live", status=200)

def readiness(request):
if time.time() < startTime + delayTime:
return HttpResponse("Waiting for ...", status=503)
else:
return HttpResponse("Ready", status=200)