# Exercise 1: Host and path routing with Ingress (easy)
#
# Prereqs: kind cluster with ingress-nginx
#   (https://kind.sigs.k8s.io/docs/user/ingress/ — create the cluster with port 80/443 mappings)
# Run: kubectl apply -n lab -f this-file.yaml
#
# Two apps already provided below: `web` and `api` (agnhost netexec echo servers).
#   TODO 1: Services `web` and `api` (port 80 → 8080)
#   TODO 2: an Ingress `petpal` (ingressClassName nginx) routing
#             petpal.localtest.me/        → web
#             api.petpal.localtest.me/v1  → api (Prefix)
#   TODO 3: rewrite so that api receives the path without the /v1 prefix
#           (ingress-nginx annotations: use-regex + rewrite-target with a capture group)
#   TODO 4: a self-signed TLS Secret (openssl or cert-manager selfSigned issuer) and a
#           tls section for both hosts; force HTTPS redirect
#
# CHECKLIST:
# [ ] curl http://petpal.localtest.me/hostname → a web Pod name
# [ ] curl http://api.petpal.localtest.me/v1/hostname → an api Pod name (rewritten to /hostname)
# [ ] curl -k https://api.petpal.localtest.me/v1/hostname works; http redirects (308).
# [ ] A comment explains which parts are portable Ingress spec vs nginx-specific annotations.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: registry.k8s.io/e2e-test-images/agnhost:2.47
          args: ["netexec", "--http-port=8080"]
          ports: [{ containerPort: 8080 }]
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 2
  selector:
    matchLabels: { app: api }
  template:
    metadata:
      labels: { app: api }
    spec:
      containers:
        - name: api
          image: registry.k8s.io/e2e-test-images/agnhost:2.47
          args: ["netexec", "--http-port=8080"]
          ports: [{ containerPort: 8080 }]
---
# TODO 1: Services
# ---
# TODO 2-4: Ingress
