# SAMMS ENTERPRISE SOVEREIGN OPERATING SYSTEM - Frontend Kubernetes Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sesos-frontend
  labels:
    app: sesos
    component: frontend
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: sesos
      component: frontend
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: sesos
        component: frontend
        version: v1
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "3000"
    spec:
      serviceAccountName: sesos-frontend
      securityContext:
        runAsNonRoot: true
        runAsUser: 1001
        fsGroup: 1001
      containers:
        - name: frontend
          image: sesos-frontend:latest
          imagePullPolicy: Always
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
          env:
            - name: NODE_ENV
              value: "production"
            - name: NEXT_PUBLIC_API_URL
              value: "https://api.sesos.example.com"
            - name: NEXT_PUBLIC_APP_URL
              value: "https://sesos.example.com"
            - name: NEXT_PUBLIC_ENVIRONMENT
              value: "production"
          resources:
            requests:
              cpu: "100m"
              memory: "256Mi"
            limits:
              cpu: "500m"
              memory: "1Gi"
          livenessProbe:
            httpGet:
              path: /api/health
              port: 3000
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /api/health
              port: 3000
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 3
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app: sesos
                    component: frontend
                topologyKey: kubernetes.io/hostname
---
apiVersion: v1
kind: Service
metadata:
  name: sesos-frontend
  labels:
    app: sesos
    component: frontend
spec:
  type: ClusterIP
  ports:
    - port: 3000
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: sesos
    component: frontend
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sesos-frontend
  labels:
    app: sesos
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: sesos-frontend-hpa
  labels:
    app: sesos
    component: frontend
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: sesos-frontend
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: sesos-frontend-pdb
  labels:
    app: sesos
    component: frontend
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: sesos
      component: frontend