# สำหรับผู้สอน — สร้าง namespace ฝึกของ Day 2
#   kubectl apply -f k8s-training-setup.yaml
#   kubectl delete namespace support-training   (หลังสอนเสร็จ)
---
apiVersion: v1
kind: Namespace
metadata:
  name: support-training
---
# 1) Workload ที่ทำงานปกติ — ใช้ฝึก View Logs / Execute Shell / Scale
apiVersion: apps/v1
kind: Deployment
metadata:
  name: healthy-web
  namespace: support-training
spec:
  replicas: 1
  selector:
    matchLabels:
      app: healthy-web
  template:
    metadata:
      labels:
        app: healthy-web
    spec:
      containers:
        - name: web
          image: nginx:1.27-alpine
          ports:
            - containerPort: 80
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              cpu: 200m
              memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
  name: healthy-web
  namespace: support-training
spec:
  selector:
    app: healthy-web
  ports:
    - port: 80
      targetPort: 80
---
# 2) Workload ที่จงใจให้พัง — tag ไม่มีอยู่จริง → ImagePullBackOff
#    ใช้ฝึกอ่าน Events (ยังไม่มี log เพราะ container ยังไม่เริ่มรัน)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: broken-image
  namespace: support-training
spec:
  replicas: 1
  selector:
    matchLabels:
      app: broken-image
  template:
    metadata:
      labels:
        app: broken-image
    spec:
      containers:
        - name: app
          image: nginx:this-tag-does-not-exist
---
# 3) Workload ที่รันแล้วพัง — ใช้ฝึก logs --previous / CrashLoopBackOff
apiVersion: apps/v1
kind: Deployment
metadata:
  name: crashing-api
  namespace: support-training
spec:
  replicas: 1
  selector:
    matchLabels:
      app: crashing-api
  template:
    metadata:
      labels:
        app: crashing-api
    spec:
      containers:
        - name: api
          image: alpine:3.20
          command:
            - sh
            - -c
            - |
              echo "[api] starting up..."
              sleep 3
              echo "[api] ERROR - cannot reach database at postgres:5432 (connection refused)" >&2
              exit 1
          resources:
            requests:
              cpu: 10m
              memory: 16Mi
            limits:
              cpu: 100m
              memory: 64Mi
