Kubernetes Interview Questions
Architecture Questions
Q: Explain the Kubernetes architecture.
Kubernetes has a master-worker architecture.
Control Plane (Master):
Worker Nodes:
Q: What is a Pod? When would you use multiple containers in one pod?
A Pod is the smallest deployable unit in Kubernetes — a group of one or more containers that share network namespace (same IP), storage volumes, and lifecycle.
Multiple containers in one pod (sidecar pattern) when containers are tightly coupled:
Rule of thumb: If two containers would always need to be on the same node and need to share localhost or volumes — same pod.
Q: Difference between Deployment, StatefulSet, DaemonSet, and Job?
| Controller | Use Case | Characteristics |
|---|
|---|---|---|
| Deployment | Stateless apps (web servers, APIs) | Random pod names, rolling updates, scales easily |
|---|---|---|
| StatefulSet | Stateful apps (databases, Kafka, ZooKeeper) | Stable pod names (pod-0, pod-1), ordered startup/shutdown, persistent volume per pod |
| DaemonSet | Node-level agents | One pod per node (or matching nodes) — log collectors, monitoring agents, CNI plugins |
| Job | Batch tasks | Runs to completion, not restarted on success |
| CronJob | Scheduled batch tasks | Creates Jobs on schedule |
Q: Explain Services — ClusterIP, NodePort, LoadBalancer, ExternalName.
| Type | Access | Use Case |
|---|
|---|---|---|
| ClusterIP (default) | Internal only (cluster DNS) | Service-to-service communication inside cluster |
|---|---|---|
| NodePort | External via NodeIP:Port (30000-32767) | Quick external access, not production |
| LoadBalancer | Cloud load balancer with external IP | Production external traffic (needs cloud provider) |
| ExternalName | CNAME alias to external DNS | Map service to external endpoint (database as a service) |
Headless Service (clusterIP: None): Returns pod IPs directly — used by StatefulSets for stable DNS names (pod-0.service.namespace.svc.cluster.local).
Q: How does Kubernetes handle rolling updates and rollbacks?
Deployment rolling update strategy:
Process: New ReplicaSet created → new pods started → old pods terminated → old RS scaled to 0.
Rollback: kubectl rollout undo deployment/app — Kubernetes keeps revision history (configurable with revisionHistoryLimit).
Q: What are ConfigMaps and Secrets? How do you use them?
ConfigMap: Store non-sensitive configuration as key-value pairs.
Usage: env vars, command args, or mounted as volume files.
Secret: Store sensitive data (base64 encoded, not encrypted by default).
Types: Opaque (generic), kubernetes.io/tls, kubernetes.io/dockerconfigjson.
Best practices for Secrets:
Q: Explain resource requests and limits. What is QoS class?
QoS Classes (affects eviction priority):
Q: What is a PersistentVolume and PersistentVolumeClaim?
PV (PersistentVolume): Cluster-level storage resource. Created by admin or dynamically by StorageClass.
PVC (PersistentVolumeClaim): Namespace-level request for storage. Pods use PVCs, not PVs directly.
StorageClass: Defines provisioner and parameters. Enables dynamic provisioning.
Access Modes: ReadWriteOnce (single node RW), ReadOnlyMany (multiple nodes RO), ReadWriteMany (multiple nodes RW — NFS, EFS).
Reclaim Policies: Retain (keep PV on PVC delete), Delete (remove PV), Recycle (deprecated).
Q: Explain RBAC in Kubernetes.
Role-Based Access Control controls who can do what to which resources.
Resources: Role (namespace-scoped), ClusterRole (cluster-wide).
Bindings: RoleBinding (binds Role or ClusterRole to user/group/SA in namespace), ClusterRoleBinding (binds ClusterRole cluster-wide).
ServiceAccount: Identity for pods. Default SA in each namespace.
Q: What are taints and tolerations? Node affinity?
Taints: Applied to nodes to repel pods that don't tolerate them.
Tolerations: Allow pods to schedule on tainted nodes.
Node Affinity: More expressive than nodeSelector.
requiredDuringSchedulingIgnoredDuringExecution: Hard rule (like nodeSelector)preferredDuringSchedulingIgnoredDuringExecution: Soft preferencePod Affinity/Anti-Affinity: Schedule pods relative to other pods (co-locate or spread).
Q: How does HPA (Horizontal Pod Autoscaler) work?
HPA watches metrics (CPU, memory, custom) and adjusts replica count.
Control loop: every 15s (default) — queries metrics API → calculates desired replicas → updates Deployment.
VPA (Vertical): Adjusts resource requests/limits.
KEDA: Event-driven autoscaling (scale on Kafka lag, SQS queue depth, etc.).
Q: How would you debug a pod that's stuck in CrashLoopBackOff?
Systematic approach:
kubectl describe pod — check Events section (image pull errors, OOMKilled, exit codes)kubectl logs --previous — logs from last crashed containerkubectl exec -it -- /bin/sh Common causes:
initialDelaySecondsScenario Questions
Q: How would you perform zero-downtime deployment?
maxUnavailable: 0 and maxSurge: 1 in rolling updateminAvailable: 1Q: A service is slow. How do you investigate?
kubectl top podskubectl logs -f deployment/appkubectl get endpoints service-name (is service routing to correct pods?)Q: How do you manage secrets securely in production Kubernetes?
--encryption-provider-config)
