K8s Interview Questions
Basic Questions:
Main components of a Kubernetes cluster?
- Master Node (API Server, Controller Manager, Scheduler, etcd)
- Worker Nodes (Kubelet, Kube Proxy, Container Runtime)
- Master Node (API Server, Controller Manager, Scheduler, etcd)
What is a Pod?
- The smallest deployable unit in Kubernetes, encapsulating one or more containers.
- The smallest deployable unit in Kubernetes, encapsulating one or more containers.
How does Kubernetes handle service discovery?
- Through Services (
ClusterIP
,NodePort
,LoadBalancer
) and DNS resolution viakube-dns
or CoreDNS.
- Through Services (
Deployment vs. DaemonSet vs. StatefulSet?
- Deployment: Manages stateless applications.
- DaemonSet: Ensures one Pod per node.
- StatefulSet: Manages stateful applications with persistent identity.
- Deployment: Manages stateless applications.
Role of etcd?
- A distributed key-value store for cluster state and configuration.
- A distributed key-value store for cluster state and configuration.
Namespaces in Kubernetes?
- Logical partitions for resource isolation within a cluster.
- Logical partitions for resource isolation within a cluster.
Service vs. Ingress?
- Service: Exposes Pods internally or externally.
- Ingress: Manages HTTP/S traffic via rules.
- Service: Exposes Pods internally or externally.
ConfigMaps vs. Secrets?
- ConfigMap: Stores non-sensitive config data.
- Secret: Stores sensitive data, encoded in Base64.
- ConfigMap: Stores non-sensitive config data.
Intermediate Questions:
What happens when a node fails?
- Pods are rescheduled on other nodes;
node-controller
detects failure.
- Pods are rescheduled on other nodes;
Rolling updates and rollbacks?
- Deployments update Pods gradually; rollbacks restore previous versions.
- Deployments update Pods gradually; rollbacks restore previous versions.
How does HPA work?
- Adjusts replica count based on CPU, memory, or custom metrics.
- Adjusts replica count based on CPU, memory, or custom metrics.
ClusterIP vs. NodePort vs. LoadBalancer?
- ClusterIP: Internal access.
- NodePort: Exposes service on node IPs.
- LoadBalancer: Uses cloud provider’s LB.
- ClusterIP: Internal access.
Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)?
- PV: A provisioned storage resource.
- PVC: A request for storage by a Pod.
- PV: A provisioned storage resource.
Readiness vs. Liveness probe?
- Readiness: Checks if Pod is ready to accept traffic.
- Liveness: Checks if Pod is alive and should restart.
- Readiness: Checks if Pod is ready to accept traffic.
kubectl exec vs. kubectl logs?
kubectl exec
: Run a command in a Pod.kubectl logs
: Fetch container logs.
How does RBAC work?
- Defines access control using
Roles
,ClusterRoles
,RoleBindings
,ClusterRoleBindings
.
- Defines access control using
Advanced Questions:
How does Kubernetes schedule Pods?
- Uses Scheduler based on node availability, resource requests, affinity rules.
- Uses Scheduler based on node availability, resource requests, affinity rules.
How to troubleshoot a failing Pod?
- Check logs (
kubectl logs
), events (kubectl describe
), and probe failures.
- Check logs (
How do Network Policies work?
- Control Pod-to-Pod and Pod-to-external traffic using rules.
- Control Pod-to-Pod and Pod-to-external traffic using rules.
What is a sidecar pattern?
- A helper container (e.g., logging, proxy) running alongside the main app in a Pod.
- A helper container (e.g., logging, proxy) running alongside the main app in a Pod.
How does Kubernetes implement multi-tenancy?
- Via Namespaces, RBAC, Network Policies, and Resource Quotas.
- Via Namespaces, RBAC, Network Policies, and Resource Quotas.
How to secure a Kubernetes cluster?
- RBAC, Network Policies, TLS, Secrets encryption, Pod Security Policies.
- RBAC, Network Policies, TLS, Secrets encryption, Pod Security Policies.
How does Istio enhance networking?
- Provides service mesh capabilities (traffic management, security, observability).
- Provides service mesh capabilities (traffic management, security, observability).
Challenges with Kubernetes in production?
- Security, networking, monitoring, resource limits, auto-scaling complexities.
- Security, networking, monitoring, resource limits, auto-scaling complexities.
TLS in an air-gapped Kubernetes cluster?
- Use cert-manager, custom CA, Vault, or manual certificate management.
- Use cert-manager, custom CA, Vault, or manual certificate management.