166 lines
2.4 KiB
Markdown
166 lines
2.4 KiB
Markdown
# Notes Application - Docker & Kubernetes Deployment
|
|
|
|
## Overview
|
|
|
|
This project is a Notes Application deployed using Docker and Kubernetes (MicroK8s).
|
|
The application allows users to:
|
|
|
|
- Create notes
|
|
- Delete notes
|
|
- Upload files
|
|
- Download files
|
|
|
|
It follows a 3-tier architecture:
|
|
|
|
- Frontend (Nginx)
|
|
- Backend (Node.js)
|
|
- Database (MongoDB)
|
|
|
|
## Architecture
|
|
|
|
```
|
|
User -> Frontend (Nginx) -> Backend (Node.js) -> MongoDB
|
|
```
|
|
|
|
## Containers
|
|
|
|
### Frontend
|
|
|
|
- Image: `nginx:alpine`
|
|
- Role: Serves static UI
|
|
- Port: `80`
|
|
|
|
### Backend
|
|
|
|
- Image: `node:18`
|
|
- Role: API server (handles notes & files)
|
|
- Port: `3000`
|
|
|
|
### Database
|
|
|
|
- Image: `mongo:6.0`
|
|
- Role: Stores notes and file data
|
|
- Port: `27017`
|
|
|
|
## Kubernetes Resources
|
|
|
|
- Namespace: `z2`
|
|
- Deployments:
|
|
- `frontend`
|
|
- `backend`
|
|
- StatefulSet:
|
|
- `mongo`
|
|
- Services:
|
|
- `frontend` (NodePort -> 30007)
|
|
- `backend` (ClusterIP)
|
|
- `mongo` (Headless Service)
|
|
|
|
## Storage
|
|
|
|
- Persistent Volume Claim: `mongo-storage`
|
|
- Size: `1Gi`
|
|
- Mount path: `/data/db`
|
|
- Purpose: Store MongoDB data persistently
|
|
|
|
## Setup Instructions
|
|
|
|
### 1. Prepare Application
|
|
|
|
```bash
|
|
./prepare-app.sh
|
|
```
|
|
|
|
- Builds Docker images
|
|
- Loads them into MicroK8s
|
|
|
|
### 2. Start Application
|
|
|
|
```bash
|
|
./start-app.sh
|
|
```
|
|
|
|
- Deploys Kubernetes resources
|
|
- Starts all services
|
|
|
|
### 3. Stop Application
|
|
|
|
```bash
|
|
./stop-app.sh
|
|
```
|
|
|
|
- Stops running pods
|
|
- Keeps configuration
|
|
|
|
### 4. Delete Application
|
|
|
|
```bash
|
|
microk8s kubectl delete all --all -n z2
|
|
microk8s kubectl delete pvc --all -n z2
|
|
```
|
|
|
|
- Removes everything including database
|
|
|
|
## Access Application
|
|
|
|
Open in browser:
|
|
|
|
```
|
|
http://<server-ip>:30007
|
|
```
|
|
|
|
Example:
|
|
|
|
```
|
|
http://147.232.204.210:30007
|
|
```
|
|
|
|
## Useful Commands
|
|
|
|
Check pods:
|
|
|
|
```bash
|
|
microk8s kubectl get pods -n z2
|
|
```
|
|
|
|
Check services:
|
|
|
|
```bash
|
|
microk8s kubectl get svc -n z2
|
|
```
|
|
|
|
View logs:
|
|
|
|
```bash
|
|
microk8s kubectl logs <pod-name> -n z2
|
|
```
|
|
|
|
## Common Issues
|
|
|
|
### Mongo Crash (version error)
|
|
|
|
Fix:
|
|
|
|
```bash
|
|
microk8s kubectl delete pvc --all -n z2
|
|
```
|
|
|
|
### Frontend shows "Welcome to nginx"
|
|
|
|
Fix:
|
|
|
|
- Ensure `index.html` is copied in Dockerfile
|
|
- Rebuild using:
|
|
|
|
```bash
|
|
./prepare-app.sh
|
|
```
|
|
|
|
## Honesty Statement
|
|
|
|
This project was developed with the assistance of AI tools (such as ChatGPT) for:
|
|
|
|
- Debugging errors
|
|
- Understanding Kubernetes concepts
|
|
- Identifying fixes for deployment issues
|
|
|
|
All configurations, testing, and final implementation were completed independently, and the AI was used strictly as a learning aid. |