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 Manifest #42

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
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
25 changes: 25 additions & 0 deletions .infrastructure/todoapp-pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: Pod
metadata:
name: todoapp
namespace: todoapp
labels:
app: todoapp
spec:
containers:
- name: todoapp
image: garimanblack/todoapp:3.0.0
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /api/liveness_check
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: /api/readiness_check
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,36 @@ 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.




# --- Apply manifests to create pods and resources:
# --- To launch a container with a ToDo application:

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

# --- To run a container with busybox (used to check the availability of your application):

kubectl apply -f .infrastructure/busybox.yml

# --- Testing the ToDo application using port-forward:

kubectl port-forward pod/todoapp 8081:8080 -n todoapp

# You can then open your browser and go to http://127.0.0.1:8081 or http://localhost:8080 to see the ToDo app.
# If you need to stop port forwarding, simply end the command with Ctrl+C

# --- Get the IP address of TodoApp:

kubectl get pods -n todoapp -0 wide

# --- Access the BusyBox shell:

kubectl -n todoapp exec -it busybox -- sh

# --- To check:

curl <Ip Address>:8080

# The busybox container will be automatically deleted when you exit it using the exit command.
12 changes: 12 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.8

WORKDIR /app

COPY . .

RUN pip install -r requirements.txt

EXPOSE 8080

ENTRYPOINT [ "sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0: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("liveness_check/", views.liveness_check, name="liveness_check"),
path("readiness_check/", views.readiness_check, name="readiness_check")
]
17 changes: 16 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


start_time = time.time()
startup_period = 20

class IsCreatorOrReadOnly(permissions.BasePermission):
"""
Object-level permission to only allow owners of an object to edit it.
Expand Down Expand Up @@ -55,4 +59,15 @@ 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_check(request):
return HttpResponse("Liveness_Active", status=200)


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