zkt25/z2/myproject/README.md
Santhosh 6a0b81d888 ssk
2025-04-30 10:02:24 +02:00

70 lines
1.8 KiB
Markdown

# Django with PostgreSQL on Kubernetes
This project demonstrates how to deploy a Django application with PostgreSQL database on Kubernetes.
## Project Structure
├── Dockerfile # Docker configuration for Django app
├── docker-compose.yml # Docker Compose configuration (if applicable)
├── k8s/ # Kubernetes configuration files
│ ├── namespace.yaml # Namespace configuration
│ ├── statefulset.yaml # PostgreSQL StatefulSet with PV/PVC
│ ├── deployment.yaml # Django application deployment
│ ├── service.yaml # Django service (NodePort)
│ ├── migrate-job.yaml # Job for Django migrations
├── manage.py # Django management script
├── myapp/ # Django app directory
├── myproject/ # Django project directory
├── requirements.txt # Python dependencies
├── scripts/ # Utility scripts
├── wait-for-it.sh # DB connection checker
└── *.sh # Various utility scripts
Utility Scripts
prepare-app.sh: Prepares the application for deployment
start-app.sh: Starts the application
stop-app.sh: Stops the application
remove-app.sh: Removes the application
stat.sh: Shows application status
wait-for-it.sh: Waits for database to be ready
## Prerequisites
- Kubernetes cluster (Minikube or cloud provider)
- kubectl configured to access your cluster
- Docker installed (for building images)
## Deployment Steps
1. **Build the Django Docker image**:
```bash
docker build -t django-app:latest .
#Troubleshooting
kubectl get pods -n webapp-namespace
kubectl logs <pod-name> -n webapp-namespace
kubectl get svc -n webapp-namespace
kubectl get pv,pvc -n webapp-namespace
#clean
kubectl delete namespace webapp-namespace
minikube service django-service --url -n webapp-namespace
kubectl exec -it postgres-0 -n webapp-namespace -- psql -U myuser -d mydatabase