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 #50

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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

*/*/__pycache__/*
*/*/*/__pycache__/*
.idea
DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/devops_todolist_kubernetes_task_3_write_a_manifest.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .infrastructure/busybox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: todoapp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the todoapp namespace exists in your Kubernetes cluster. If it doesn't, you need to create it or change this to a namespace that does exist.

spec:
containers:
- name: busybox
image: ikulyk404/busyboxplus:curl
imagePullPolicy: IfNotPresent
args:
- sleep
- "1000"
4 changes: 4 additions & 0 deletions .infrastructure/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: todoapp
28 changes: 28 additions & 0 deletions .infrastructure/todoapp-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v1
kind: Pod
metadata:
name: todoapp
labels:
role: todoapp
spec:
containers:
- name: todoapp
image: vpcomtek/todoapp:3.0.0
imagePullPolicy: IfNotPresent
ports:
- name: todoapp
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: api/liveness
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: api/readiness
port: 8080
initialDelaySeconds: 5
periodSeconds: 5

12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.8

WORKDIR /app

COPY ./src /app

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"]
32 changes: 32 additions & 0 deletions INSTRUCTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Instruction
### How to Apply All Manifests
```
kubectl apply -f .infrastructure/namespace.yml
kubectl apply -f .infrastructure/busybox.yml
kubectl apply -f .infrastructure/todoapp-pod.yml
```
### Testing ToDo Application Using port-forward
```
kubectl port-forward pod/todoapp -n todoapp 8000:8000
```
- Visit http://localhost:8000 to access the application.
### Testing Application Using busyboxplus:curl
```
kubectl exec -it busybox -n todoapp -- curl http://todoapp:8000
kubectl exec -it busybox -n todoapp -- curl http://todoapp:8000/readiness
kubectl exec -it busybox -n todoapp -- curl http://todoapp:8000/liveness
```
or

1. Retrieve the IP address of the TodoApp pod:
```
kubectl get pods -n todoapp -o wide
```
2. Access the BusyBox shell:
```
kubectl -n todoapp exec -it busybox -- sh
```
3. Send a curl request to the TodoApp:
```
curl <TodoApp_IP_address>: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 @@ -55,4 +55,17 @@ 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)

start_time = time.time()
delay_time = 40

def readiness (request):
if time.time() < start_time + delay_time:
return HttpResponse("Not ready", status=503)
else:
return HttpResponse("Ready", status=200)

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