# Kubernetes Deployment for SwarmCare Documentation
# Phase 09: Production-Ready Documentation Services
# Version: 2.1
# Last Updated: 2025-10-28

---
apiVersion: v1
kind: Namespace
metadata:
  name: swarmcare-docs
  labels:
    name: swarmcare-docs
    phase: "09"

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: docs-sa
  namespace: swarmcare-docs

---
# MkDocs Documentation Service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mkdocs-server
  namespace: swarmcare-docs
  labels:
    app: swarmcare-docs
    component: mkdocs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: swarmcare-docs
      component: mkdocs
  template:
    metadata:
      labels:
        app: swarmcare-docs
        component: mkdocs
    spec:
      serviceAccountName: docs-sa
      containers:
        - name: mkdocs
          image: swarmcare/mkdocs:2.1
          ports:
            - containerPort: 8000
              name: http
          resources:
            requests:
              cpu: "500m"
              memory: "512Mi"
            limits:
              cpu: "1"
              memory: "1Gi"
          livenessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 30
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 5
            periodSeconds: 5

---
apiVersion: v1
kind: Service
metadata:
  name: mkdocs-server
  namespace: swarmcare-docs
spec:
  selector:
    app: swarmcare-docs
    component: mkdocs
  ports:
    - port: 80
      targetPort: 8000
  type: ClusterIP

---
# Sphinx Documentation Service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sphinx-server
  namespace: swarmcare-docs
  labels:
    app: swarmcare-docs
    component: sphinx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: swarmcare-docs
      component: sphinx
  template:
    metadata:
      labels:
        app: swarmcare-docs
        component: sphinx
    spec:
      serviceAccountName: docs-sa
      containers:
        - name: sphinx
          image: swarmcare/sphinx:2.1
          ports:
            - containerPort: 8080
              name: http
          resources:
            requests:
              cpu: "500m"
              memory: "512Mi"
            limits:
              cpu: "1"
              memory: "1Gi"

---
apiVersion: v1
kind: Service
metadata:
  name: sphinx-server
  namespace: swarmcare-docs
spec:
  selector:
    app: swarmcare-docs
    component: sphinx
  ports:
    - port: 80
      targetPort: 8080
  type: ClusterIP

---
# API Documentation (Swagger/ReDoc)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-docs-server
  namespace: swarmcare-docs
  labels:
    app: swarmcare-docs
    component: api-docs
spec:
  replicas: 2
  selector:
    matchLabels:
      app: swarmcare-docs
      component: api-docs
  template:
    metadata:
      labels:
        app: swarmcare-docs
        component: api-docs
    spec:
      serviceAccountName: docs-sa
      containers:
        - name: swagger-ui
          image: swaggerapi/swagger-ui:latest
          ports:
            - containerPort: 8080
              name: http
          env:
            - name: SWAGGER_JSON
              value: /openapi/openapi.yaml
          resources:
            requests:
              cpu: "250m"
              memory: "256Mi"
            limits:
              cpu: "500m"
              memory: "512Mi"

---
apiVersion: v1
kind: Service
metadata:
  name: api-docs-server
  namespace: swarmcare-docs
spec:
  selector:
    app: swarmcare-docs
    component: api-docs
  ports:
    - port: 80
      targetPort: 8080
  type: ClusterIP

---
# Ingress for Documentation Services
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: docs-ingress
  namespace: swarmcare-docs
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
    - hosts:
        - docs.swarmcare.io
      secretName: docs-tls
  rules:
    - host: docs.swarmcare.io
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: mkdocs-server
                port:
                  number: 80
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-docs-server
                port:
                  number: 80
          - path: /technical
            pathType: Prefix
            backend:
              service:
                name: sphinx-server
                port:
                  number: 80

---
# Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: mkdocs-hpa
  namespace: swarmcare-docs
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: mkdocs-server
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
