Kubernetes Interview Q&A

1. What is Kubernetes and why do we use it?

Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications. It helps manage multiple containers across multiple hosts ensuring high availability, auto-scaling, and zero downtime deployments.

2. What is the difference between a Pod and a Container?

A Pod is the smallest deployable unit in Kubernetes that can contain one or more containers sharing the same network namespace and storage. Containers are individual runtime environments within Pods.

3. What is a ReplicaSet?

ReplicaSet ensures that a specified number of identical Pods are running at any given time. If one Pod fails, it automatically creates a new one.

4. What is a Deployment?

A Deployment is a higher-level abstraction that manages ReplicaSets and provides features like rolling updates, rollbacks, and versioned application deployments.

5. Difference between StatefulSet and Deployment?

Deployment is used for stateless applications, while StatefulSet manages stateful applications with stable identities, persistent storage, and ordered scaling.

6. What is a DaemonSet and where is it used?

DaemonSet ensures that one copy of a specific Pod runs on each node. It is used for deploying monitoring agents, log collectors, or security tools.

7. Give a real-time use case for DaemonSet.

To deploy a node monitoring agent like Node Exporter on every worker node automatically whenever a new node is added to the cluster.

8. What are Kubernetes Services and their types?

Services expose Pods to the network. Types include ClusterIP (internal), NodePort (external static port), LoadBalancer (cloud external access), and ExternalName (maps to external DNS).

9. What is Ingress and why is it used?

Ingress manages external HTTP/HTTPS access to services inside the cluster using routing rules like path-based and host-based routing, and can handle SSL termination.

10. Scenario: Two applications on same port 80 — how to expose both?

Use an Ingress Controller with path-based routing such as '/app1' to service1 and '/app2' to service2 instead of NodePort.

11. What are Volumes in Kubernetes?

Volumes provide persistent storage to containers and ensure data is retained even after container restarts. Types include emptyDir, hostPath, EBS, and EFS.

12. Difference between EmptyDir, HostPath, EBS, and EFS?

EmptyDir is ephemeral; HostPath uses node storage; EBS provides persistent block storage to one node; EFS allows multi-node access and shared data.

13. What is a Persistent Volume (PV) and Persistent Volume Claim (PVC)?

A PV is cluster-level storage provisioned by an admin; a PVC is a request for storage by a user. PVCs automatically bind to PVs based on resource requirements.

14. What is a StorageClass?

StorageClass defines how storage is dynamically provisioned in Kubernetes, allowing automatic PV creation when a PVC is requested.

15. Scenario: Pod stuck in 'Pending' state — what could be the reasons?

Common reasons: No node with required resources, unbound PVC, taints on nodes, or affinity/selector mismatch.

16. Scenario: Pod keeps restarting — how to debug?

Check logs using 'kubectl logs', describe pod for events, verify probes and resource limits, and inspect for OOMKill or crash loops.

17. What are Liveness and Readiness Probes?

Liveness probe checks if container is healthy; Readiness probe checks if container is ready to serve traffic. Misconfigurations can cause restarts or missed traffic.

18. What is an Init Container?

Init containers run before main containers to perform setup tasks like checking dependencies or downloading configurations.

19. What are ConfigMaps and Secrets?

ConfigMaps store non-sensitive data like configuration files. Secrets store sensitive data such as credentials and tokens (base64 encoded).

20. Scenario: How to store AWS credentials securely for pods?

Create a Kubernetes Secret and mount it into the Pod as environment variables or as a volume.

21. What is a Namespace in Kubernetes?

Namespaces logically isolate cluster resources. Common examples: dev, test, and prod environments.

22. Scenario: How do you restrict resource usage per namespace?

Use ResourceQuota and LimitRange objects to define CPU, memory, and object limits per namespace.

23. What are Resource Requests and Limits?

Requests define minimum guaranteed resources; Limits define maximum resources. Exceeding limits can cause OOMKill.

24. What is Horizontal Pod Autoscaler (HPA)?

HPA automatically adjusts the number of pod replicas based on metrics like CPU or memory usage.

25. Scenario: How to perform zero-downtime deployment?

Use Deployment with RollingUpdate strategy. Kubernetes replaces old Pods gradually while keeping the service available.

26. What is a CrashLoopBackOff error?

It means the Pod is repeatedly crashing and restarting. Common causes include bad configuration, failed dependencies, or probe misconfigurations.

27. What is the difference between 'kubectl apply', 'create', and 'replace'?

Create adds new resources, Apply creates or updates declaratively, and Replace overwrites existing resources completely.

28. How do you expose a service to the internet in a multi-node cluster?

Use Service type LoadBalancer or configure Ingress Controller. In cloud (EKS/GKE/AKS), a load balancer is created automatically.

29. Scenario: How to roll back a faulty deployment?

Use 'kubectl rollout undo deployment <deployment>' and check previous versions using 'kubectl rollout history'.

30. Real-time Scenario: Application logs not visible — how to debug?

Check logs with 'kubectl logs', inspect log collectors like Fluentd or Promtail, and ensure log volume mounts are configured properly.

31. Scenario: Pod stuck in ImagePullBackOff — how do you fix it?

Check image name and tag correctness. If private registry, verify imagePullSecrets. Run 'kubectl describe pod' to see image pull errors.

32. Scenario: Node shows 'NotReady' — what could be the issue?

Common causes: Kubelet service stopped, network plugin (CNI) failure, or disk pressure. Run 'systemctl status kubelet' and 'kubectl describe node'.

33. Scenario: Service not accessible externally — what to check?

Ensure Service type is NodePort/LoadBalancer, firewall rules allow the port, and correct targetPort is exposed in the Pod spec.

34. Scenario: PVC not bound to PV — what’s the reason?

Mismatch in accessModes, storageClass, or size. Verify using 'kubectl describe pvc'. Ensure a matching PV is available.

35. Scenario: DNS not resolving inside Pod — how to troubleshoot?

Check CoreDNS Pod status. Run 'kubectl get pods -n kube-system'. Verify 'resolv.conf' inside Pod and ensure ClusterIP for kube-dns is reachable.

36. Scenario: Application slow — what to check in Kubernetes?

Inspect CPU/memory usage, network latency, HPA settings, and check for resource throttling or node-level bottlenecks.

37. Scenario: Deployment rollout stuck — how to fix?

Run 'kubectl rollout status deployment'. Check Pod readiness probe failures or insufficient resources blocking new Pod creation.

38. Scenario: Container OOMKilled — what causes it?

Container exceeded its memory limit. Increase memory limit in manifest or optimize app memory usage. Check 'kubectl describe pod' events.

39. Scenario: Intermittent Pod network failures — how to resolve?

Check CNI plugin logs (Flannel/Calico). Verify IP conflicts or MTU mismatch. Restart CNI Pods if misconfigured.

40. Scenario: ConfigMap changes not reflected — why?

Pods don't auto-reload updated ConfigMaps. Redeploy or restart Pods using 'kubectl rollout restart deployment <name>'.