diff --git a/.infrastructure/clusterip.yml b/.infrastructure/clusterip.yml new file mode 100644 index 0000000..8d08c9b --- /dev/null +++ b/.infrastructure/clusterip.yml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: todoapp-clusterip + namespace: todoapp +spec: + selector: + app: todolist + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: ClusterIP diff --git a/.infrastructure/nodeport.yml b/.infrastructure/nodeport.yml new file mode 100644 index 0000000..89641ad --- /dev/null +++ b/.infrastructure/nodeport.yml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: todoapp-nodeport + namespace: todoapp +spec: + type: NodePort + selector: + app: todolist + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + nodePort: 30007 diff --git a/.infrastructure/todoapp-pod.yml b/.infrastructure/todoapp-pod.yml index b1e4f8b..d0574fe 100644 --- a/.infrastructure/todoapp-pod.yml +++ b/.infrastructure/todoapp-pod.yml @@ -1,8 +1,37 @@ apiVersion: v1 kind: Pod metadata: - name: todoapp + name: todoapp-0 namespace: todoapp + labels: + app: todolist +spec: + containers: + - name: todoapp + image: ikulyk404/todoapp:3.0.0 + 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 + +--- +apiVersion: v1 +kind: Pod +metadata: + name: todoapp-1 + namespace: todoapp + labels: + app: todolist spec: containers: - name: todoapp diff --git a/README.md b/README.md index 981fe53..b68fa32 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,46 @@ -# Django ToDo list +# Kubernetes TodoApp Deployment -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: - -- 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): +## 1. Apply the manifests to create the namespace, TodoApp pods, and BusyBox pod: +Run the following command to apply all manifests within the ./.infrastructure directory: +```bash +kubectl apply -f ./.infrastructure ``` -pip install -r requirements.txt + +Or apply each manifest individually as follows: +```bash +kubectl apply -f ./.infrastructure/namespace.yml +kubectl apply -f ./.infrastructure/clusterip.yml +kubectl apply -f ./.infrastructure/nodeport.yml +kubectl apply -f ./.infrastructure/busybox.yml +kubectl apply -f ./.infrastructure/todoapp-pod.yml ``` -Create a database schema: +## 2. Test the TodoApp using the ClusterIP service: +To test the TodoApp via the ClusterIP service, follow these steps: + +1. Access the BusyBox shell: +```bash +kubectl -n todoapp exec -it busybox -- sh ``` -python manage.py migrate + +2. Send a curl request to the ClusterIP service DNS: +```bash +curl http://todoapp-clusterip.todoapp.svc.cluster.local ``` +This should return a response from the TodoApp if it’s running correctly. -And then start the server (default is http://localhost:8000): +## 3. Test the TodoApp using port-forwarding: +1. Test the TodoApp locally, use port-forwarding to access the service: +```bash +kubectl port-forward service/todoapp-clusterip 8080:80 -n todoapp ``` -python manage.py runserver -``` - -Now you can browse the [API](http://localhost:8000/api/) or start on the [landing page](http://localhost:8000/). -## Task +2. Open your web browser and test the TodoApp at: +http://localhost:8080 -Create a kubernetes manifest for a pod which will containa ToDo app container: +## 3. Test the TodoApp using the NodePort service in your web browser at: -1. Fork this repository. -1. Modify pod manifest to deploy a second same pod with a different name. -1. Add labels to pods “app: todolist” -1. Create a manifest for a ClusterIP service, which should balance traffic between two pods -1. Create a manifest for a NodePort service, which should expose an application on a Node Level -1. Set all env values for the container from pod’s manifest -1. `README.md` should contain instructions on how to test an app by calling a ClusterIP service DNS from a busybox container -1. `README.md` file should contain instructions on how to test ToDo application using the service `port-forward` command -1. `README.md` should contain instruction on how to access an app using a NodePort Service -1. Create PR with your changes and attach it for validation on a platform. +http://localhost:30007