# Exercise 2: Deployment + Service with zero-downtime rollouts (medium)
#
# Run: kubectl create namespace lab && kubectl apply -n lab -f this-file.yaml
#
# Deploy `hello` (image registry.k8s.io/e2e-test-images/agnhost:2.47 with args
# ["netexec", "--http-port=8080"]) behind a ClusterIP Service.
#   TODO 1: Deployment with 4 replicas, selector/labels app=hello
#   TODO 2: RollingUpdate with maxSurge 1, maxUnavailable 0, minReadySeconds 5,
#           progressDeadlineSeconds 120, revisionHistoryLimit 3
#   TODO 3: readiness probe HTTP GET / on port http (every 3 s),
#           resources (requests 50m/32Mi, limit memory 64Mi)
#   TODO 4: preStop sleep 5 and terminationGracePeriodSeconds 30
#   TODO 5: Service `hello` port 80 → targetPort http
#   TODO 6: topologySpreadConstraints spreading Pods across nodes (maxSkew 1,
#           whenUnsatisfiable ScheduleAnyway)
#
# Then, while running a load loop from a busybox Pod
#   (while true; do wget -qO- -T1 http://hello/hostname || echo FAIL; done)
# change the image to agnhost:2.48 and apply. You should see zero FAIL lines.
# Finally, deploy a broken image tag and show the rollout stalls without downtime,
# then `kubectl rollout undo`.
#
# CHECKLIST:
# [ ] 4/4 Pods ready, Service has 4 endpoints.
# [ ] Rollout to 2.48 completes with no FAIL lines in the load loop.
# [ ] Broken tag → ImagePullBackOff on 1 new Pod, old Pods keep serving,
#     `rollout status` times out after progressDeadlineSeconds.
# [ ] `rollout undo` restores the previous ReplicaSet.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 1   # TODO 1
  selector:
    matchLabels:
      app: hello
  # TODO 2: strategy, minReadySeconds, progressDeadlineSeconds, revisionHistoryLimit
  template:
    metadata:
      labels:
        app: hello
    spec:
      # TODO 4: terminationGracePeriodSeconds
      # TODO 6: topologySpreadConstraints
      containers:
        - name: hello
          image: registry.k8s.io/e2e-test-images/agnhost:2.47
          args: ["netexec", "--http-port=8080"]
          ports:
            - containerPort: 8080
              name: http
          # TODO 3: readinessProbe, resources
          # TODO 4: lifecycle.preStop
---
# TODO 5: Service
