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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.IntermediateWrite a CronJob that runs a backup every night at 02:00 and keeps limited history.Intermediate