This commit is contained in:
Tour
2025-12-03 19:03:03 +01:00
parent 4c32043e5f
commit 8e06e20b70
12 changed files with 2232 additions and 76 deletions

189
k8s/README.md Normal file
View File

@@ -0,0 +1,189 @@
# Kubernetes Deployment for Auction Monitor
## Quick Start
### 1. Build and Push Docker Image
```bash
# Build image
docker build -t your-registry/auction-monitor:latest .
# Push to registry
docker push your-registry/auction-monitor:latest
```
### 2. Update deployment.yaml
Edit `deployment.yaml` and replace:
- `image: auction-monitor:latest` with your image
- `auction-monitor.yourdomain.com` with your domain
### 3. Deploy to Kubernetes
```bash
# Apply all resources
kubectl apply -f k8s/deployment.yaml
# Or apply individually
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml
```
### 4. Verify Deployment
```bash
# Check pods
kubectl get pods -n auction-monitor
# Check services
kubectl get svc -n auction-monitor
# Check ingress
kubectl get ingress -n auction-monitor
# View logs
kubectl logs -f deployment/auction-monitor -n auction-monitor
```
### 5. Access Application
```bash
# Port forward for local access
kubectl port-forward svc/auction-monitor 8081:8081 -n auction-monitor
# Access API
curl http://localhost:8081/api/monitor/status
# Access health check
curl http://localhost:8081/health/live
```
## Configuration
### ConfigMap
Edit workflow schedules in `configMap`:
```yaml
data:
AUCTION_WORKFLOW_SCRAPER_IMPORT_CRON: "0 */30 * * * ?" # Every 30 min
AUCTION_WORKFLOW_IMAGE_PROCESSING_CRON: "0 0 * * * ?" # Every 1 hour
AUCTION_WORKFLOW_BID_MONITORING_CRON: "0 */15 * * * ?" # Every 15 min
AUCTION_WORKFLOW_CLOSING_ALERTS_CRON: "0 */5 * * * ?" # Every 5 min
```
### Secrets
Update notification configuration:
```bash
# Create secret
kubectl create secret generic auction-secrets \
--from-literal=notification-config='smtp:user@gmail.com:password:recipient@example.com' \
-n auction-monitor
# Or edit existing
kubectl edit secret auction-secrets -n auction-monitor
```
## Scaling
### Manual Scaling
```bash
# Scale to 3 replicas
kubectl scale deployment auction-monitor --replicas=3 -n auction-monitor
```
### Auto Scaling
HPA is configured in `deployment.yaml`:
```yaml
spec:
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
averageUtilization: 80
```
View HPA status:
```bash
kubectl get hpa -n auction-monitor
```
## Monitoring
### Health Checks
```bash
# Liveness
kubectl exec -it deployment/auction-monitor -n auction-monitor -- \
wget -qO- http://localhost:8081/health/live
# Readiness
kubectl exec -it deployment/auction-monitor -n auction-monitor -- \
wget -qO- http://localhost:8081/health/ready
```
### Logs
```bash
# Follow logs
kubectl logs -f deployment/auction-monitor -n auction-monitor
# Logs from all pods
kubectl logs -f -l app=auction-monitor -n auction-monitor
# Previous pod logs
kubectl logs deployment/auction-monitor --previous -n auction-monitor
```
## Troubleshooting
### Pod not starting
```bash
# Describe pod
kubectl describe pod -l app=auction-monitor -n auction-monitor
# Check events
kubectl get events -n auction-monitor --sort-by='.lastTimestamp'
```
### Database issues
```bash
# Check PVC
kubectl get pvc -n auction-monitor
# Check volume mount
kubectl exec -it deployment/auction-monitor -n auction-monitor -- ls -la /data
```
### Network issues
```bash
# Test service
kubectl run -it --rm debug --image=busybox --restart=Never -n auction-monitor -- \
wget -qO- http://auction-monitor:8081/health/live
```
## Cleanup
```bash
# Delete all resources
kubectl delete -f k8s/deployment.yaml
# Or delete namespace (removes everything)
kubectl delete namespace auction-monitor
```

197
k8s/deployment.yaml Normal file
View File

@@ -0,0 +1,197 @@
apiVersion: v1
kind: Namespace
metadata:
name: auction-monitor
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: auction-data-pvc
namespace: auction-monitor
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
name: auction-config
namespace: auction-monitor
data:
AUCTION_DATABASE_PATH: "/data/cache.db"
AUCTION_IMAGES_PATH: "/data/images"
AUCTION_NOTIFICATION_CONFIG: "desktop"
QUARKUS_HTTP_PORT: "8081"
QUARKUS_HTTP_HOST: "0.0.0.0"
# Workflow schedules (cron expressions)
AUCTION_WORKFLOW_SCRAPER_IMPORT_CRON: "0 */30 * * * ?"
AUCTION_WORKFLOW_IMAGE_PROCESSING_CRON: "0 0 * * * ?"
AUCTION_WORKFLOW_BID_MONITORING_CRON: "0 */15 * * * ?"
AUCTION_WORKFLOW_CLOSING_ALERTS_CRON: "0 */5 * * * ?"
---
apiVersion: v1
kind: Secret
metadata:
name: auction-secrets
namespace: auction-monitor
type: Opaque
stringData:
# Replace with your actual SMTP configuration
notification-config: "desktop"
# For email: smtp:your@gmail.com:app_password:recipient@example.com
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: auction-monitor
namespace: auction-monitor
labels:
app: auction-monitor
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: auction-monitor
template:
metadata:
labels:
app: auction-monitor
version: v1
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8081"
prometheus.io/path: "/q/metrics"
spec:
containers:
- name: auction-monitor
image: auction-monitor:latest
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8081
protocol: TCP
env:
- name: JAVA_OPTS
value: "-Xmx256m -XX:+UseParallelGC"
envFrom:
- configMapRef:
name: auction-config
- secretRef:
name: auction-secrets
volumeMounts:
- name: data
mountPath: /data
- name: models
mountPath: /app/models
readOnly: true
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health/live
port: 8081
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 3
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/ready
port: 8081
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
startupProbe:
httpGet:
path: /health/started
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 30
volumes:
- name: data
persistentVolumeClaim:
claimName: auction-data-pvc
- name: models
emptyDir: {} # Or mount from ConfigMap/PVC if you have YOLO models
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: auction-monitor
namespace: auction-monitor
labels:
app: auction-monitor
spec:
type: ClusterIP
ports:
- port: 8081
targetPort: 8081
protocol: TCP
name: http
selector:
app: auction-monitor
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: auction-monitor-ingress
namespace: auction-monitor
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
ingressClassName: nginx
tls:
- hosts:
- auction-monitor.yourdomain.com
secretName: auction-monitor-tls
rules:
- host: auction-monitor.yourdomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: auction-monitor
port:
number: 8081
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: auction-monitor-hpa
namespace: auction-monitor
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: auction-monitor
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80