Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Fix this broken Deployment YAML.

BeginnerHands-onWrite-a-Kubernetes-manifest tasks
Answer

Broken:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: "2"
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
      - name: api
        image: myrepo/api:1.0
        ports:
        - containerPort: "8080"

Fixed:

spec:
  replicas: 2
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: myrepo/api:1.0
          ports:
            - containerPort: 8080

Key trick → Three bugs: replicas and containerPort must be integers, not strings, and the template label app: backend doesn't match the selector, which the API server rejects with selector does not match template labels. Run kubectl apply --dry-run=server -f to catch these before applying.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks