apiVersion: apps/v1
kind: Deployment
metadata:
  name: cms
spec:
  template:
    spec:
      containers:
        - name: cms
          resources:
            requests:
              cpu: {{ K8S_CMS_CPU_REQUEST }}
              memory: {{ K8S_CMS_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_CMS_CPU_LIMIT }}
              memory: {{ K8S_CMS_MEMORY_LIMIT }}
          {% if K8S_OPENEDX_HEALTH_PROBES_ENABLE %}
          startupProbe:
            httpGet:
              path: /heartbeat
              port: 8000
              httpHeaders:
                - name: Host
                  value: cms
            periodSeconds: {{ K8S_OPENEDX_STARTUP_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_STARTUP_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_STARTUP_PROBE_FAILURE_THRESHOLD }}
          # Readiness defaults to a TCP check for the same reason as liveness
          # below. /heartbeat verifies MySQL and the modulestore, which every
          # replica shares, so a stalled database fails the probe on all replicas
          # at once. That empties the Service endpoints and the ingress starts
          # refusing connections: a dependency slowdown becomes a total outage,
          # with every pod healthy but unreachable. Restarting nothing is small
          # comfort when no request can land.
          # The startupProbe above already gates traffic on a real /heartbeat
          # before the pod first joins the Service, which is what readiness was
          # introduced for. Set K8S_OPENEDX_READINESS_PROBE_USE_HEARTBEAT to opt
          # back in to dependency-aware readiness.
          readinessProbe:
            {% if K8S_OPENEDX_READINESS_PROBE_USE_HEARTBEAT %}
            httpGet:
              path: /heartbeat
              port: 8000
              httpHeaders:
                - name: Host
                  value: cms
            {% else %}
            tcpSocket:
              port: 8000
            {% endif %}
            periodSeconds: {{ K8S_OPENEDX_READINESS_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_READINESS_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_READINESS_PROBE_FAILURE_THRESHOLD }}
          # Liveness deliberately does NOT use /heartbeat: that endpoint checks
          # MySQL and the modulestore, which are shared by every pod. A brief
          # database outage would fail liveness on all replicas at once and
          # Kubernetes would kill the entire deployment. A TCP check answers the
          # only question liveness should ask: is this uwsgi process wedged?
          # Dependency health belongs on readinessProbe, which sheds traffic
          # without destroying the pod.
          livenessProbe:
            tcpSocket:
              port: 8000
            periodSeconds: {{ K8S_OPENEDX_LIVENESS_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_LIVENESS_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_LIVENESS_PROBE_FAILURE_THRESHOLD }}
          {% endif %}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cms-worker
spec:
  template:
    spec:
      containers:
        - name: cms-worker
          resources:
            requests:
              cpu: {{ K8S_CMS_WORKER_CPU_REQUEST }}
              memory: {{ K8S_CMS_WORKER_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_CMS_WORKER_CPU_LIMIT }}
              memory: {{ K8S_CMS_WORKER_MEMORY_LIMIT }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lms
spec:
  template:
    spec:
      containers:
        - name: lms
          resources:
            requests:
              cpu: {{ K8S_LMS_CPU_REQUEST }}
              memory: {{ K8S_LMS_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_LMS_CPU_LIMIT }}
              memory: {{ K8S_LMS_MEMORY_LIMIT }}
          {% if K8S_OPENEDX_HEALTH_PROBES_ENABLE %}
          startupProbe:
            httpGet:
              path: /heartbeat
              port: 8000
              httpHeaders:
                - name: Host
                  value: lms
            periodSeconds: {{ K8S_OPENEDX_STARTUP_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_STARTUP_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_STARTUP_PROBE_FAILURE_THRESHOLD }}
          # See the note on the cms readinessProbe above: readiness must not
          # depend on MySQL or the modulestore, or a database stall empties the
          # Service endpoints on every replica at once and the site goes dark.
          readinessProbe:
            {% if K8S_OPENEDX_READINESS_PROBE_USE_HEARTBEAT %}
            httpGet:
              path: /heartbeat
              port: 8000
              httpHeaders:
                - name: Host
                  value: lms
            {% else %}
            tcpSocket:
              port: 8000
            {% endif %}
            periodSeconds: {{ K8S_OPENEDX_READINESS_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_READINESS_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_READINESS_PROBE_FAILURE_THRESHOLD }}
          # See the note on the cms livenessProbe above: liveness must not depend
          # on MySQL or the modulestore, or a database blip takes down every pod.
          livenessProbe:
            tcpSocket:
              port: 8000
            periodSeconds: {{ K8S_OPENEDX_LIVENESS_PROBE_PERIOD_SECONDS }}
            timeoutSeconds: {{ K8S_OPENEDX_LIVENESS_PROBE_TIMEOUT_SECONDS }}
            failureThreshold: {{ K8S_OPENEDX_LIVENESS_PROBE_FAILURE_THRESHOLD }}
          {% endif %}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lms-worker
spec:
  template:
    spec:
      containers:
        - name: lms-worker
          resources:
            requests:
              cpu: {{ K8S_LMS_WORKER_CPU_REQUEST }}
              memory: {{ K8S_LMS_WORKER_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_LMS_WORKER_CPU_LIMIT }}
              memory: {{ K8S_LMS_WORKER_MEMORY_LIMIT }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mfe
spec:
  template:
    spec:
      containers:
        - name: mfe
          resources:
            requests:
              cpu: {{ K8S_MFE_CPU_REQUEST }}
              memory: {{ K8S_MFE_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_MFE_CPU_LIMIT }}
              memory: {{ K8S_MFE_MEMORY_LIMIT }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: caddy
spec:
  template:
    spec:
      containers:
        - name: caddy
          resources:
            requests:
              cpu: {{ K8S_CADDY_CPU_REQUEST }}
              memory: {{ K8S_CADDY_MEMORY_REQUEST }}
            limits:
              cpu: {{ K8S_CADDY_CPU_LIMIT }}
              memory: {{ K8S_CADDY_MEMORY_LIMIT }}
