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

Members can save this page, take notes and track progress. See membership · Sign in

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

← All Kubernetes questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake