Kubernetes interview question · Most asked
Write a Kubernetes Deployment and Service for a web API with probes, resource requests and a rolling update strategy.
Hands-on Asked in DevOps Engineer · Site Reliability Engineer (SRE) · Cloud Engineer interviews
Summary
A Deployment with several replicas, a readiness probe that gates traffic, a liveness probe for deadlocks, resource requests (for scheduling) and memory limits, a rolling update that never drops below capacity, a graceful shutdown delay, and a ClusterIP Service selecting the pods.
Longer Answer
Points to explain: maxUnavailable: 0 keeps capacity during rollouts; the preStop sleep lets endpoints update
before SIGTERM; liveness probes should be cheap and not depend on databases; CPU limits are often omitted to avoid
throttling, but memory limits stay.
Example
apiVersion: apps/v1
kind: Deployment
metadata: { name: api, labels: { app: api } }
spec:
replicas: 3
strategy: { type: RollingUpdate, rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } }
selector: { matchLabels: { app: api } }
template:
metadata: { labels: { app: api } }
spec:
terminationGracePeriodSeconds: 30
containers:
- name: api
image: ghcr.io/acme/api:3f2c9e1
ports: [{ containerPort: 8000 }]
resources:
requests: { cpu: 250m, memory: 256Mi }
limits: { memory: 512Mi }
readinessProbe: { httpGet: { path: /ready, port: 8000 }, periodSeconds: 5 }
livenessProbe: { httpGet: { path: /live, port: 8000 }, initialDelaySeconds: 10, periodSeconds: 10 }
lifecycle: { preStop: { exec: { command: ["sleep", "5"] } } }
---
apiVersion: v1
kind: Service
metadata: { name: api }
spec:
selector: { app: api }
ports: [{ port: 80, targetPort: 8000 }]
Key Points
- Readiness gates traffic; liveness restarts.
- Requests for scheduling; memory limits.
- maxUnavailable 0, maxSurge 1.
- preStop delay for graceful shutdown.
- Service selects by labels.
Explanation
What interviewers look for
Production-ready manifests and the reasoning behind each setting.
More Kubernetes questions
- What is the difference between resource requests and limits, and what are the QoS classes?
- How do you make pods shut down gracefully without dropping requests?
- Deployment, StatefulSet, DaemonSet, Job and CronJob: when do you use each?
- How does the scheduler place pods? Explain resource requests, node affinity, taints and tolerations.
- Describe the Kubernetes architecture: what runs on the control plane and what runs on the nodes?
- What are Kubernetes namespaces, when should you create them, and what isolation do they provide?
- What happens, step by step, when you run kubectl apply for a Deployment?
- A pod is in CrashLoopBackOff. How do you debug it?