Fix Kubernetes scheduling issue by optimizing deployment configuration

This commit is contained in:
Automated Action 2025-06-05 23:45:44 +00:00
parent d084731477
commit e92d783de4
3 changed files with 188 additions and 2 deletions

View File

@ -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 <pod-name>
kubectl get events --sort-by='.metadata.creationTimestamp'
```

View File

@ -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

11
kubernetes/pvc.yaml Normal file
View File

@ -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