# Exercise 1: A StatefulSet with per-Pod storage (medium)
#
# Run on kind (uses the built-in `standard` StorageClass, rancher local-path):
#   kubectl create ns db && kubectl apply -n db -f this-file.yaml
#
# Run a 3-replica Redis StatefulSet where each Pod keeps its own data.
#   TODO 1: headless Service `redis` (port 6379)
#   TODO 2: StatefulSet `redis` with serviceName redis, 3 replicas, image redis:7.4,
#           command redis-server --appendonly yes, data mounted at /data
#   TODO 3: volumeClaimTemplates `data`: RWO, 1Gi, storageClassName standard
#   TODO 4: readinessProbe exec `redis-cli ping`; resources requests 50m/64Mi, limit 128Mi
#   TODO 5: PodDisruptionBudget allowing at most 1 Pod unavailable
#   TODO 6: podManagementPolicy Parallel? — decide and justify in a comment
#
# Experiments:
#   a) kubectl exec redis-1 -- redis-cli set pet rex; delete Pod redis-1; after it
#      returns, redis-cli get pet → rex
#   b) From a busybox Pod: nslookup redis-0.redis.db.svc.cluster.local and nslookup redis
#   c) Scale to 1 and back to 3 — are PVCs data-redis-1/2 deleted? Is the data still there?
#
# CHECKLIST:
# [ ] kubectl get pvc -n db shows data-redis-0/1/2 Bound.
# [ ] Data survives Pod deletion (same PVC re-attached to the same ordinal).
# [ ] Per-Pod DNS names resolve; `redis` resolves to 3 Pod IPs (headless).
# [ ] PVCs are retained after scale-down (persistentVolumeClaimRetentionPolicy default).
# [ ] Comment explains why this is NOT yet a replicated Redis (no replication config).
apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  selector:
    app: redis
  ports:
    - port: 6379
  # TODO 1: headless
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
spec:
  serviceName: redis
  replicas: 1   # TODO 2
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
        - name: redis
          image: redis:7.4
          # TODO 2: command, ports, volumeMounts
          # TODO 4: readinessProbe, resources
  # TODO 3: volumeClaimTemplates
---
# TODO 5: PodDisruptionBudget
# TODO 6: decision + justification
