apiVersion: apps/v1
kind: Deployment
metadata:
  name: ia-service
  labels:
    app: ia-service
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ia-service
  template:
    metadata:
      labels:
        app: ia-service
    spec:
      containers:
      - name: ia-service
        image: ia-service:latest
        ports:
        - containerPort: 80
        env:
        - name: APP_ENV
          value: "prod"
        - name: APP_SECRET
          valueFrom:
            secretKeyRef:
              name: ia-service-secrets
              key: app-secret
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: ia-service-secrets
              key: database-url
        - name: OPENAI_API_KEY
          valueFrom:
            secretKeyRef:
              name: ia-service-secrets
              key: openai-api-key
        - name: REDIS_URL
          value: "redis://redis-service:6379"
        - name: MAIN_APP_BASE_URL
          value: "https://cours2facu.varascundo.com"
        - name: CORS_ALLOW_ORIGIN
          value: "^https://cours2facu\\.varascundo\\.com$"
        livenessProbe:
          httpGet:
            path: /health
            port: 80
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
---
apiVersion: v1
kind: Service
metadata:
  name: ia-service
spec:
  selector:
    app: ia-service
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ia-service-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
  - hosts:
    - api.cours2facu.varascundo.com
    secretName: ia-service-tls
  rules:
  - host: api.cours2facu.varascundo.com
    http:
      paths:
      - path: /ia
        pathType: Prefix
        backend:
          service:
            name: ia-service
            port:
              number: 80