Deploy the broken app

Running Agentic / Platform Engineering Assistant / lab 1 of 7View on GitHub

Deploy the Application

From the root of this repo, create the namespace first, then apply the rest of the manifests:

kubectl apply -f the-broken-apps/pe-assistant-app/namespace.yaml
kubectl apply -f the-broken-apps/pe-assistant-app/

Symptoms You Might Encounter:

  • Pods failing to start or in CrashLoopBackOff
  • Services unable to connect to pods
  • Ingress routing not working
  • Configuration mismatches
  • Resource constraint violations

Testing the Application

  1. Port-forward to access the apps
Port-forward to test services directly
kubectl port-forward -n pe-assistant svc/frontend 8080:80
kubectl port-forward -n pe-assistant svc/backend 8081:3000
  1. Add entry to /etc/hosts (if using local cluster)
echo "127.0.0.1 pe-assistant.local" | sudo tee -a /etc/hosts
  1. Test the frontend
curl http://pe-assistant.local
  1. Test the API through ingress
curl http://pe-assistant.local/api
backend-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  namespace: pe-assistant
  labels:
    app: backend
    tier: backend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: backend
      # Bug 1: Mismatched label selector (missing tier label)
  template:
    metadata:
      labels:
        app: backend
        tier: backend
    spec:
      containers:
      - name: api
        image: hashicorp/http-echo:latest
        args:
        - "-text=Hello from Backend API"
        - "-listen=:8080"
        ports:
        - containerPort: 8080
          name: http
        env:
        - name: REDIS_HOST
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: REDIS_HOST
        - name: REDIS_PORT
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: REDIS_PORT
        - name: LOG_LEVEL
          value: "debug"
        resources:
          requests:
            memory: "64Mi"
            cpu: "50m"
          limits:
            memory: "128Mi"
            cpu: "100m"
        livenessProbe:
          httpGet:
            path: /
            port: 8080
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 10
      # Bug 3: Missing service account or security context that might be needed
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
configmap.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: pe-assistant
data:
  BACKEND_SERVICE_URL: "http://backend:3000"
  REDIS_HOST: "redis"
  REDIS_PORT: "6379"
  APP_ENV: "production"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  namespace: pe-assistant
data:
  default.conf: |
    server {
        listen 80;
        server_name _;

        location / {
            root /usr/share/nginx/html;
            index index.html;
            try_files $uri $uri/ /index.html;
        }

        location /api {
            proxy_pass http://backend:3000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

        location /health {
            access_log off;
            return 200 "healthy\n";
            add_header Content-Type text/plain;
        }
    }
frontend-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
  namespace: pe-assistant
  labels:
    app: frontend
    tier: frontend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: frontend
      tier: frontend
  template:
    metadata:
      labels:
        app: frontend
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80
          name: http
        env:
        - name: BACKEND_URL
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: BACKEND_SERVICE_URL
        resources:
          requests:
            # Bug 2: Memory request typo (should be 128Mi)
            memory: "128M"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "200m"
        livenessProbe:
          httpGet:
            path: /health
            port: 80
          initialDelaySeconds: 10
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        volumeMounts:
        - name: nginx-config
          mountPath: /etc/nginx/conf.d
      volumes:
      - name: nginx-config
        configMap:
          name: nginx-config
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pe-assistant-ingress
  namespace: pe-assistant
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    # Bug 1: Invalid annotation value
    nginx.ingress.kubernetes.io/ssl-redirect: "yes"
spec:
  ingressClassName: nginx
  rules:
  - host: pe-assistant.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: frontend
            port:
              number: 80
      - path: /api
        # Bug 2: Wrong pathType (should be Prefix for /api routes)
        pathType: Exact
        backend:
          service:
            name: backend
            port:
              number: 3000
namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: pe-assistant
  labels:
    app: pe-assistant
redis-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: pe-assistant
  labels:
    app: redis
    tier: cache
spec:
  # Bug 1: Multiple replicas for Redis without clustering (should be 1)
  replicas: 2
  selector:
    matchLabels:
      app: redis
      tier: cache
  template:
    metadata:
      labels:
        app: redis
        tier: cache
    spec:
      containers:
      - name: redis
        image: redis:6.2-alpine
        ports:
        - containerPort: 6379
          name: redis
        command:
        - redis-server
        # Bug 2: Invalid Redis configuration argument
        - "--maxmemory 100mb"
        - "--maxmemory-policy allkeys-lru"
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "200m"
        livenessProbe:
          tcpSocket:
            port: 6379
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          exec:
            command:
            - redis-cli
            - ping
          initialDelaySeconds: 5
          periodSeconds: 10
        volumeMounts:
        - name: redis-data
          # Bug 3: Wrong mount path for Redis data
          mountPath: /data/redis
      volumes:
      - name: redis-data
        emptyDir: {}
services.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
  namespace: pe-assistant
  labels:
    app: frontend
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: http
    protocol: TCP
    name: http
  selector:
    app: frontend
    tier: frontend
---
apiVersion: v1
kind: Service
metadata:
  name: backend
  namespace: pe-assistant
  labels:
    app: backend
spec:
  type: ClusterIP
  ports:
  # Bug 1: Service port mismatch with container port
  - port: 3000
    targetPort: 8080
    protocol: TCP
    name: http
  selector:
    app: backend
    tier: backend
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: pe-assistant
  labels:
    app: redis
spec:
  # Bug 2: Wrong service type for internal cache (should be ClusterIP)
  type: NodePort
  ports:
  - port: 6379
    targetPort: 6379
    protocol: TCP
    name: redis
    # Bug 3: NodePort specified but not in valid range or conflicts
    nodePort: 30000
  selector:
    app: redis
    # Bug 4: Missing tier label in selector