From e92d783de475f12d1fc62068a3d7a10cee7e8d63 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 5 Jun 2025 23:45:44 +0000 Subject: [PATCH] Fix Kubernetes scheduling issue by optimizing deployment configuration --- README.md | 89 ++++++++++++++++++++++++++++++++++++- kubernetes/deployment.yaml | 90 ++++++++++++++++++++++++++++++++++++++ kubernetes/pvc.yaml | 11 +++++ 3 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 kubernetes/deployment.yaml create mode 100644 kubernetes/pvc.yaml diff --git a/README.md b/README.md index e8acfba..0786cd7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,88 @@ -# FastAPI Application +# Small Business Inventory Management System -This is a FastAPI application bootstrapped by BackendIM, the AI-powered backend generation platform. +This is a FastAPI application for managing small business inventory, products, orders, and suppliers. + +## Features + +- User authentication and authorization +- Product management +- Inventory tracking +- Order processing +- Supplier management +- Category organization + +## API Endpoints + +- `/docs` - Swagger UI documentation +- `/redoc` - ReDoc documentation +- `/health` - Health check endpoint +- `/api/v1/auth` - Authentication endpoints +- `/api/v1/users` - User management +- `/api/v1/products` - Product management +- `/api/v1/inventory` - Inventory management +- `/api/v1/orders` - Order processing +- `/api/v1/suppliers` - Supplier management +- `/api/v1/categories` - Category management + +## Running Locally + +1. Install dependencies: + ``` + pip install -r requirements.txt + ``` + +2. Start the server: + ``` + uvicorn main:app --host 0.0.0.0 --port 8000 --reload + ``` + +## Environment Variables + +The application uses the following environment variables: + +- `SECRET_KEY`: Secret key for JWT token generation +- `SERVER_NAME`: Server name (e.g., "Inventory Management System") +- `SERVER_HOST`: Server host URL (e.g., "https://inventory.example.com") +- `FIRST_SUPERUSER`: Email for the first superuser +- `FIRST_SUPERUSER_PASSWORD`: Password for the first superuser + +## Kubernetes Deployment + +The application can be deployed using Kubernetes with the provided configuration files in the `kubernetes/` directory: + +- `deployment.yaml`: Deployment configuration (using name `prod-pod`) +- `service.yaml`: Service configuration (using name `prod-pod-service`) +- `pvc.yaml`: Persistent Volume Claim for storage +- `secrets.yaml`: Secret configuration for environment variables + +### Deployment Notes + +- Optimized for reliable scheduling on resource-constrained clusters: + - Reduced replicas to 1 to ensure easier scheduling + - Reduced resource requests and limits + - Changed image pull policy to IfNotPresent to reduce pull issues + - Added flexible tolerations to run on nodes with any taints + - Configured node affinity for Linux but as a preference, not a requirement + - Set empty storageClassName to use the cluster's default storage class + +- If you experience the "pod does not have a host assigned" error: + - Check that your cluster has available nodes with sufficient resources + - Verify that the default storage class exists and is working + - Ensure the specified image exists and is accessible + +To deploy: + +```bash +kubectl apply -f kubernetes/secrets.yaml +kubectl apply -f kubernetes/pvc.yaml +kubectl apply -f kubernetes/deployment.yaml +kubectl apply -f kubernetes/service.yaml +``` + +To check the status: + +```bash +kubectl get pods +kubectl describe pod +kubectl get events --sort-by='.metadata.creationTimestamp' +``` diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 0000000..2133f59 --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,90 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prod-pod + labels: + app: inventory-api +spec: + replicas: 1 # Reduced replicas to 1 to ensure easier scheduling + selector: + matchLabels: + app: inventory-api + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: inventory-api + spec: + containers: + - name: app + image: ${IMAGE_REPOSITORY}:${IMAGE_TAG} + imagePullPolicy: IfNotPresent # Changed from Always to IfNotPresent to reduce pull issues + resources: + requests: + cpu: "50m" # Reduced CPU request + memory: "128Mi" # Reduced memory request + limits: + cpu: "300m" # Reduced CPU limit + memory: "384Mi" # Reduced memory limit + ports: + - containerPort: 8000 + name: http + env: + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: inventory-api-secrets + key: secret-key + - name: SERVER_NAME + value: "Inventory Management System" + - name: SERVER_HOST + value: "https://inventory.example.com" + - name: FIRST_SUPERUSER + value: "admin@example.com" + - name: FIRST_SUPERUSER_PASSWORD + valueFrom: + secretKeyRef: + name: inventory-api-secrets + key: admin-password + livenessProbe: + httpGet: + path: /health + port: 8000 + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /health + port: 8000 + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 3 + failureThreshold: 3 + volumeMounts: + - name: storage-volume + mountPath: /app/storage + volumes: + - name: storage-volume + persistentVolumeClaim: + claimName: inventory-api-pvc + # Enhanced tolerations to allow more flexible scheduling + tolerations: + - operator: "Exists" # This will tolerate all taints + # Affinity settings to help with scheduling + affinity: + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + preference: + matchExpressions: + - key: "kubernetes.io/os" + operator: In + values: + - linux + # No nodeSelector to allow maximum scheduling flexibility \ No newline at end of file diff --git a/kubernetes/pvc.yaml b/kubernetes/pvc.yaml new file mode 100644 index 0000000..0968a5e --- /dev/null +++ b/kubernetes/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: inventory-api-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: "" # Empty string to use the default storage class \ No newline at end of file