Complete infrastructure: CitrineOS+OpenADR+FM integration, asset sync, scheduling, IaC scripts, K8s manifests, documentation
This commit is contained in:
339
iac/k8s/README.md
Normal file
339
iac/k8s/README.md
Normal file
@@ -0,0 +1,339 @@
|
||||
# Cariflex EMS - Kubernetes Manifests
|
||||
|
||||
## Namespace
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: cariflex
|
||||
labels:
|
||||
app: cariflex-ems
|
||||
environment: production
|
||||
```
|
||||
|
||||
## ConfigMap
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: cariflex-config
|
||||
namespace: cariflex
|
||||
data:
|
||||
# FlexMeasures
|
||||
FM_ENV: "production"
|
||||
FM_LOG_LEVEL: "WARNING"
|
||||
FM_DB_HOST: "postgres-service"
|
||||
FM_REDIS_HOST: "redis-service"
|
||||
|
||||
# OpenADR
|
||||
VTN_ID: "Cariflex-VTN"
|
||||
VEN_ID: "Cariflex-VEN"
|
||||
VTN_PORT: "8080"
|
||||
|
||||
# CitrineOS
|
||||
CITRINEOS_ENV: "production"
|
||||
AMQP_HOST: "rabbitmq-service"
|
||||
AMQP_PORT: "5672"
|
||||
DB_HOST: "citrineos-postgres-service"
|
||||
```
|
||||
|
||||
## Secrets
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: cariflex-secrets
|
||||
namespace: cariflex
|
||||
type: Opaque
|
||||
stringData:
|
||||
FM_SECRET_KEY: "${FM_SECRET_KEY}"
|
||||
FM_DB_PASSWORD: "${FM_DB_PASSWORD}"
|
||||
REDIS_PASSWORD: "${REDIS_PASSWORD}"
|
||||
CITRINEOS_DB_PASSWORD: "${CITRINEOS_DB_PASSWORD}"
|
||||
RABBITMQ_PASSWORD: "${RABBITMQ_PASSWORD}"
|
||||
```
|
||||
|
||||
## FlexMeasures Deployment
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: flexmeasures-server
|
||||
namespace: cariflex
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: flexmeasures-server
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: flexmeasures-server
|
||||
spec:
|
||||
containers:
|
||||
- name: flexmeasures
|
||||
image: lfenergy/flexmeasures:latest
|
||||
ports:
|
||||
- containerPort: 5000
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: cariflex-config
|
||||
- secretRef:
|
||||
name: cariflex-secrets
|
||||
resources:
|
||||
requests:
|
||||
memory: "1Gi"
|
||||
cpu: "500m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "2"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/v3_0/sensors
|
||||
port: 5000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/v3_0/sensors
|
||||
port: 5000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: flexmeasures-service
|
||||
namespace: cariflex
|
||||
spec:
|
||||
selector:
|
||||
app: flexmeasures-server
|
||||
ports:
|
||||
- port: 5000
|
||||
targetPort: 5000
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
## OpenADR VTN Deployment
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: openadr-vtn
|
||||
namespace: cariflex
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: openadr-vtn
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: openadr-vtn
|
||||
spec:
|
||||
containers:
|
||||
- name: vtn
|
||||
image: flexmeasures-openadr-vtn:latest
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: cariflex-config
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: openadr-vtn-service
|
||||
namespace: cariflex
|
||||
spec:
|
||||
selector:
|
||||
app: openadr-vtn
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
## OpenADR VEN Deployment
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: openadr-ven
|
||||
namespace: cariflex
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: openadr-ven
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: openadr-ven
|
||||
spec:
|
||||
containers:
|
||||
- name: ven
|
||||
image: flexmeasures-openadr-ven:latest
|
||||
env:
|
||||
- name: VTN_URL
|
||||
value: "http://openadr-vtn-service:8080/OpenADR2/Simple/2.0b"
|
||||
- name: FM_HOST
|
||||
value: "https://cariflex.digitribe.fr"
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: cariflex-config
|
||||
- secretRef:
|
||||
name: cariflex-secrets
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: openadr-ven-service
|
||||
namespace: cariflex
|
||||
spec:
|
||||
selector:
|
||||
app: openadr-ven
|
||||
ports:
|
||||
- port: 8080
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
## CitrineOS Deployment
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: citrineos-server
|
||||
namespace: cariflex
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: citrineos-server
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: citrineos-server
|
||||
spec:
|
||||
containers:
|
||||
- name: citrineos
|
||||
image: ghcr.io/citrineos/citrineos-server:latest
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: cariflex-config
|
||||
- secretRef:
|
||||
name: cariflex-secrets
|
||||
resources:
|
||||
requests:
|
||||
memory: "512Mi"
|
||||
cpu: "250m"
|
||||
limits:
|
||||
memory: "1Gi"
|
||||
cpu: "1"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: citrineos-service
|
||||
namespace: cariflex
|
||||
spec:
|
||||
selector:
|
||||
app: citrineos-server
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
## Ingress
|
||||
```yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: cariflex-ingress
|
||||
namespace: cariflex
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- cariflex.digitribe.fr
|
||||
- grafana.digitribe.fr
|
||||
- citrineos.digitribe.fr
|
||||
secretName: cariflex-tls
|
||||
rules:
|
||||
- host: cariflex.digitribe.fr
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: flexmeasures-service
|
||||
port:
|
||||
number: 5000
|
||||
- host: grafana.digitribe.fr
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: grafana-service
|
||||
port:
|
||||
number: 3000
|
||||
- host: citrineos.digitribe.fr
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: citrineos-service
|
||||
port:
|
||||
number: 8080
|
||||
```
|
||||
|
||||
## Deployment Commands
|
||||
```bash
|
||||
# Create namespace
|
||||
kubectl apply -f k8s/namespace.yaml
|
||||
|
||||
# Apply config and secrets
|
||||
kubectl apply -f k8s/configmap.yaml
|
||||
kubectl apply -f k8s/secrets.yaml
|
||||
|
||||
# Deploy applications
|
||||
kubectl apply -f k8s/deployments/flexmeasures.yaml
|
||||
kubectl apply -f k8s/deployments/openadr-vtn.yaml
|
||||
kubectl apply -f k8s/deployments/openadr-ven.yaml
|
||||
kubectl apply -f k8s/deployments/citrineos.yaml
|
||||
|
||||
# Apply services
|
||||
kubectl apply -f k8s/services/
|
||||
|
||||
# Apply ingress
|
||||
kubectl apply -f k8s/ingress.yaml
|
||||
|
||||
# Verify
|
||||
kubectl get pods -n cariflex
|
||||
kubectl get svc -n cariflex
|
||||
kubectl get ingress -n cariflex
|
||||
```
|
||||
142
iac/scripts/deploy.sh
Normal file
142
iac/scripts/deploy.sh
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/bin/bash
|
||||
# Cariflex EMS - Multi-Environment Deployment Script
|
||||
# Usage: ./deploy.sh [dev|test|prod] [full|fm|openadr|citrine|grafana]
|
||||
|
||||
set -e
|
||||
|
||||
ENV="${1:-dev}"
|
||||
COMPONENT="${2:-full}"
|
||||
CARIFLEX_HOME="/home/eric/cariflex"
|
||||
FLEXMEASURES_HOME="/home/eric/flexmeasures"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() { echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"; }
|
||||
warn() { echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING:${NC} $1"; }
|
||||
error() { echo -e "${RED}[$(date +'%Y-%m-%d %H:%M-%S')] ERROR:${NC} $1"; exit 1; }
|
||||
|
||||
# Environment-specific configuration
|
||||
case "$ENV" in
|
||||
dev)
|
||||
FM_DOMAIN="cariflex.dev.local"
|
||||
GRAFANA_DOMAIN="grafana.dev.local"
|
||||
CITRINEOS_DOMAIN="citrineos.dev.local"
|
||||
REPLICAS=1
|
||||
DEBUG=true
|
||||
LOG_LEVEL="DEBUG"
|
||||
;;
|
||||
test)
|
||||
FM_DOMAIN="cariflex.test.digitribe.fr"
|
||||
GRAFANA_DOMAIN="grafana.test.digitribe.fr"
|
||||
CITRINEOS_DOMAIN="citrineos.test.digitribe.fr"
|
||||
REPLICAS=1
|
||||
DEBUG=false
|
||||
LOG_LEVEL="INFO"
|
||||
;;
|
||||
prod)
|
||||
FM_DOMAIN="cariflex.digitribe.fr"
|
||||
GRAFANA_DOMAIN="grafana.digitribe.fr"
|
||||
CITRINEOS_DOMAIN="citrineos.digitribe.fr"
|
||||
REPLICAS=2
|
||||
DEBUG=false
|
||||
LOG_LEVEL="WARNING"
|
||||
;;
|
||||
*)
|
||||
error "Unknown environment: $ENV (use dev, test, or prod)"
|
||||
;;
|
||||
esac
|
||||
|
||||
log "Deploying Cariflex EMS to $ENV environment"
|
||||
log "Component: $COMPONENT"
|
||||
log "FM Domain: $FM_DOMAIN"
|
||||
log "Replicas: $REPLICAS"
|
||||
|
||||
# Function to deploy a docker-compose stack
|
||||
deploy_stack() {
|
||||
local compose_file="$1"
|
||||
local stack_name="$2"
|
||||
|
||||
log "Deploying $stack_name from $compose_file..."
|
||||
|
||||
# Generate environment-specific override
|
||||
cat > "/tmp/docker-compose.${ENV}.override.yml" << EOF
|
||||
version: '3.8'
|
||||
services:
|
||||
server:
|
||||
environment:
|
||||
- LOGGING_LEVEL=${LOG_LEVEL}
|
||||
- FLEXMEASURES_ENV=${ENV}
|
||||
labels:
|
||||
- "traefik.http.routers.${stack_name}.rule=Host(\`${FM_DOMAIN}\`)"
|
||||
EOF
|
||||
|
||||
# Deploy
|
||||
docker compose -f "$compose_file" -f "/tmp/docker-compose.${ENV}.override.yml" up -d
|
||||
|
||||
log "$stack_name deployed successfully"
|
||||
}
|
||||
|
||||
# Deploy based on component
|
||||
case "$COMPONENT" in
|
||||
full)
|
||||
log "Deploying full stack..."
|
||||
deploy_stack "$FLEXMEASURES_HOME/docker-compose.yml" "flexmeasures"
|
||||
deploy_stack "$FLEXMEASURES_HOME/docker-compose.openadr.yml" "openadr"
|
||||
deploy_stack "$CARIFLEX_HOME/config/docker-compose-citrineos.yml" "citrineos"
|
||||
;;
|
||||
fm)
|
||||
deploy_stack "$FLEXMEASURES_HOME/docker-compose.yml" "flexmeasures"
|
||||
;;
|
||||
openadr)
|
||||
deploy_stack "$FLEXMEASURES_HOME/docker-compose.openadr.yml" "openadr"
|
||||
;;
|
||||
citrine)
|
||||
deploy_stack "$CARIFLEX_HOME/config/docker-compose-citrineos.yml" "citrineos"
|
||||
;;
|
||||
*)
|
||||
error "Unknown component: $COMPONENT (use full, fm, openadr, citrine)"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Health checks
|
||||
log "Running health checks..."
|
||||
|
||||
check_service() {
|
||||
local name="$1"
|
||||
local url="$2"
|
||||
local max_attempts="${3:-30}"
|
||||
|
||||
for i in $(seq 1 $max_attempts); do
|
||||
if curl -sk "$url" > /dev/null 2>&1; then
|
||||
log "$name is healthy"
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
warn "$name health check failed after ${max_attempts} attempts"
|
||||
return 1
|
||||
}
|
||||
|
||||
check_service "FlexMeasures" "https://${FM_DOMAIN}/api/v3_0/sensors" 30
|
||||
check_service "OpenADR VTN" "http://openadr-vtn:8080/OpenADR2/Simple/2.0b" 10
|
||||
check_service "CitrineOS" "http://cariflex-citrineos-server:8080" 10
|
||||
|
||||
# Summary
|
||||
log "Deployment complete!"
|
||||
log ""
|
||||
log "Environment: $ENV"
|
||||
log "URLs:"
|
||||
log " FlexMeasures: https://${FM_DOMAIN}"
|
||||
log " Grafana: https://${GRAFANA_DOMAIN}"
|
||||
log " CitrineOS: https://${CITRINEOS_DOMAIN}"
|
||||
log ""
|
||||
log "Containers:"
|
||||
docker ps --format " {{.Names}}: {{.Status}}" | grep -E "flexmeasures|openadr|citrine|grafana"
|
||||
|
||||
# Cleanup
|
||||
rm -f "/tmp/docker-compose.${ENV}.override.yml"
|
||||
Reference in New Issue
Block a user