Kubernetes Architecture, Operations, and Troubleshooting Questions
How Kubernetes works, how to run it, and how to debug it. Covers control-plane and node components, the scheduler and API server, cluster design, high availability and multi-cluster topologies, and platform-level operations; the workload primitives (pods, deployments, services, controllers), cluster upgrades, and designing Kubernetes as an internal platform; and the operational depth inside a cluster including pod and service networking, ingress and the CNI model, service mesh, persistent volumes and storage classes, resource requests and limits, and systematically diagnosing scheduling, networking, and storage failures. The full architecture-through-day-two-operations span of Kubernetes.
List common cloud and network-backed storage options used with Kubernetes (examples: AWS EBS, AWS EFS, GCE PD, Azure Disk, NFS) and briefly describe trade-offs in terms of performance, durability, multi-node attach, and typical use-cases.
Sample Answer
Cloud and network-backed storage for Kubernetes splits into two families: block storage (AWS EBS, GCE PD, Azure Disk), which is fast and durable but normally attachable to only one node at a time, and network filesystems (AWS EFS, Azure Files, self-managed NFS), which are shareable across many nodes at once but pay a latency and throughput cost for that flexibility. Picking between them is really picking whether the workload needs raw single-writer performance or multi-node shared access.
Comparison
| Option | Performance | Durability | Multi-node attach | Typical use case |
|---|---|---|---|---|
| AWS EBS (Elastic Block Store) | High IOPS (input/output operations per second) and throughput on provisioned tiers; low latency | Replicated within the Availability Zone by AWS | Single-writer (ReadWriteOnce) for ordinary use; a Multi-Attach mode exists for specific volume types but requires a cluster-aware filesystem and is the exception, not the default | Databases, single-node stateful workloads |
| AWS EFS (Elastic File System) | Network filesystem; throughput scales with configured mode but per-operation latency is higher and more variable than block storage | Replicated across multiple Availability Zones by AWS | ReadWriteMany: many Pods across many nodes can mount concurrently | Shared config/assets, CI caches, content shared across replicas |
| GCE PD (Persistent Disk) | Strong block performance; low latency within a zone | Zonal by default; a regional PD variant replicates synchronously across two zones for higher availability | Single-writer for normal use; a multi-writer mode exists on specific disk types but is restricted and still expects the application to coordinate writes itself, since it is not a cluster filesystem | Databases, single-node stateful apps |
| Azure Disk | High IOPS/throughput on Premium/Ultra tiers | Replicated within the region/zone by Azure | Single-writer (ReadWriteOnce) | Block storage for VMs/Pods needing high, predictable performance |
| Azure Files | SMB/NFS network filesystem semantics | Managed, replicated by Azure | ReadWriteMany | Shared config, home directories, app assets |
| NFS (self-managed) | Depends entirely on the server and network path; can become a shared bottleneck | Depends on how the operator makes the NFS server itself highly available; no built-in durability beyond what you build | ReadWriteMany | Simple shared storage, legacy applications expecting a shared filesystem |
How to choose
- Single-writer, latency-sensitive, durable (a relational database's primary, a message queue's log): block storage (EBS, GCE PD, Azure Disk). Access mode ReadWriteOnce, sized and provisioned for the IOPS the workload actually needs.
- Shared, multi-reader-or-writer, latency-tolerant (shared configuration, static assets, a CI build cache used by many concurrent jobs): a managed network filesystem (EFS, Azure Files) if available on your cloud, or self-managed NFS if not, understanding that NFS's durability and availability are now your responsibility to engineer.
- Regional or multi-zone resilience for a block-storage workload: look at the provider's own cross-zone replication option (GCE's regional Persistent Disk is the clearest example) rather than assuming ordinary zonal block storage survives a zone failure; ordinary zonal EBS/PD/Azure Disk does not.
Worked example
A team needs (a) a primary Postgres (Postgres) volume and (b) a shared directory of report templates read by 20 replica Pods across multiple nodes.
- (a) is single-writer and latency-sensitive: provision an EBS/GCE PD/Azure Disk volume through a StorageClass with
ReadWriteOnce, sized for the database's IOPS profile. - (b) needs concurrent multi-node reads: provision an EFS/Azure Files/NFS volume through a StorageClass supporting
ReadWriteMany, since a block-storage volume cannot satisfy that access pattern at all, regardless of performance tier.
Trade-offs and pitfalls
- Don't reach for a network filesystem by default "to be safe" for multi-node access; if the workload is genuinely single-writer, block storage's lower latency is the better fit and the shared-filesystem's variability is pure downside.
- Zonal block storage (the common case for EBS/GCE PD/Azure Disk) does not survive the loss of its Availability Zone; if that's a real requirement, either use the provider's cross-zone replicated variant where one exists, or handle replication at the application layer (e.g., a database's own streaming replication to a replica in another zone) rather than assuming the storage layer covers it.
- A "multi-writer" flag on a block-storage product is not the same guarantee as a real shared filesystem: it typically still requires a cluster-aware filesystem and application-level write coordination, so verify exactly what's supported for your disk type before relying on it, rather than assuming ReadWriteMany-equivalent behavior.
What is a StorageClass in Kubernetes and what are its most important fields (for example provisioner, parameters, reclaimPolicy, volumeBindingMode)? Explain dynamic versus static provisioning and when you would mark a StorageClass as the cluster default.
Sample Answer
A StorageClass is a cluster-scoped object that tells Kubernetes how to dynamically create storage for a PersistentVolumeClaim (PVC, a namespaced request for storage): which driver provisions it, what parameters to pass that driver, and what happens to the underlying volume when its claim is deleted.
The important fields
| Field | What it controls |
|---|---|
provisioner | Which CSI (Container Storage Interface, the standard plugin interface storage drivers implement) driver creates volumes for this class, for example ebs.csi.aws.com |
parameters | Driver-specific settings passed straight through: disk type, IOPS, filesystem type, encryption, availability zone constraints |
reclaimPolicy | Delete (default for dynamically provisioned volumes): the underlying storage is destroyed when its PVC is deleted. Retain: the storage and its data are kept, and an admin has to manually clean it up |
volumeBindingMode | Immediate (default): the PersistentVolume is provisioned and bound as soon as the PVC is created. WaitForFirstConsumer: binding is delayed until a Pod that will actually use the PVC is scheduled |
allowVolumeExpansion | Whether a PVC using this class can later be resized larger |
mountOptions | Optional mount flags passed to the volume at mount time |
How the CSI model makes this work
The provisioner field names a CSI driver, the standard interface Kubernetes uses so any storage vendor can plug in a compliant driver without Kubernetes needing vendor-specific code built in. In practice, a CSI driver ships as a controller-side component (which handles create/delete/attach requests, typically via sidecar containers like external-provisioner and external-attacher that watch PVC and VolumeAttachment objects and translate them into gRPC calls against the actual driver) and a node-side component (a DaemonSet that mounts the resulting volume into the Pod on whichever node it lands on). The StorageClass is the configuration Kubernetes hands to that controller-side component whenever a PVC requests dynamic provisioning.
Dynamic vs static provisioning
- Dynamic: a PVC references a StorageClass; the CSI provisioner creates a matching PersistentVolume automatically. This is the default, recommended path, since it needs no manual admin step per volume and scales with the number of workloads.
- Static: an admin pre-creates PersistentVolumes ahead of time (for pre-existing storage, special hardware, or a resource that can't be provisioned on demand), and a PVC binds to one of them by matching capacity and access mode. No StorageClass is required for static binding, though a PVC can still be written to only match pre-provisioned volumes by leaving
storageClassNameunset or matching it explicitly.
Why WaitForFirstConsumer and Retain matter for multi-AZ clusters
volumeBindingMode: WaitForFirstConsumer: withImmediatebinding in a multi-zone cluster, the provisioner can create a volume in Zone A before the scheduler has decided where the Pod will actually run; if the scheduler then places the Pod in Zone B (because that's where capacity or other constraints point), the Pod is stuck Pending forever, since most block storage can't attach across zones.WaitForFirstConsumerfixes this by waiting until the Pod is scheduled first, then provisioning the volume in the same zone the Pod actually landed in.reclaimPolicy: Retain: in a multi-AZ, stateful-workload context, an accidental PVC deletion (a badkubectl delete, a mistaken namespace teardown) with the defaultDeletepolicy destroys the underlying data immediately and irreversibly.Retaintrades convenience for a manual recovery path: the storage and its data survive, and an admin can inspect, snapshot, or manually rebind it before anything is actually destroyed. Production stateful workloads (databases especially) commonly override the default toRetainfor exactly this reason.
Small worked fragment
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-multiaz
provisioner: ebs.csi.aws.com
parameters:
type: gp3
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
When to mark a StorageClass as the cluster default
Mark a class as default only when it's the right choice for the majority of workloads that don't specify one explicitly, typically a general-purpose, moderate-cost, moderate-performance tier. Don't default to a niche, expensive, or retention-sensitive class (a high-IOPS tier, or anything using Retain) since Pods that forget to specify a class would silently get an unexpectedly costly or hard-to-clean-up volume. Critical workloads should reference their StorageClass explicitly regardless of what's marked default, so a later change to the cluster default can't silently change their storage tier out from under them.
Trade-offs and pitfalls
- Having more than one StorageClass marked default is a real, common misconfiguration; Kubernetes doesn't reliably pick one for you, and PVCs that omit
storageClassNamecan end up on whichever one the admission logic happens to select. reclaimPolicy: Deletecombined with a fast, careless cleanup script is the most common way production data gets destroyed accidentally;Retainis the safer default for anything holding data you can't regenerate.WaitForFirstConsumerdelays seeing a bound PersistentVolume until a Pod actually exists, which can be confusing during manual troubleshooting if you expect to see an immediately-bound PV the moment you create a PVC.
Explain Kubernetes NetworkPolicy at a high level. What problems does it solve, how are ingress and egress policies expressed, how do selectors and namespaceSelectors work, and what is the default behavior when no policies are defined?
Sample Answer
NetworkPolicy is a namespaced Kubernetes object that restricts which pods can talk to which other pods (and, via egress rules, which external destinations pods can reach), solving east-west traffic control inside the cluster: without it, any pod can reach any other pod by default, which is a large blast radius for a compromised or misconfigured workload.
The enforcement point that isn't the API server
Creating a NetworkPolicy object only stores intent in etcd via the API server, the same as any other Kubernetes object; the API server itself does not inspect or block a single packet. Enforcement is entirely the responsibility of the CNI (container network interface) plugin running on each node, and only if that plugin actually implements NetworkPolicy support. Calico, Cilium, and several others do; a purely overlay-focused CNI like plain Flannel historically does not. Applying a NetworkPolicy on a cluster whose CNI doesn't enforce it is a silent no-op: kubectl get networkpolicy shows the object as created, but traffic flows exactly as if it didn't exist. Confirming the CNI's NetworkPolicy support is a prerequisite, not an afterthought, before relying on this mechanism for anything security-relevant.
Expressing ingress and egress
A policy selects pods with podSelector, and, once selected, ingress and egress traffic is governed independently:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: web-policy
spec:
podSelector:
matchLabels: { app: web }
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector: { matchLabels: { role: frontend } }
ports:
- port: 80
egress:
- to:
- namespaceSelector: { matchLabels: { env: services } }
ports:
- port: 5432
This says: pods labeled app: web accept ingress only from pods labeled role: frontend on port 80, and may only send egress to pods in namespaces labeled env: services on port 5432. Everything else in that direction is implicitly denied once any rule for that direction exists.
Selectors and namespaceSelector
podSelectorinsidefrom/tomatches pods by label within the same namespace as the rule's target namespace context.namespaceSelectormatches whole namespaces by label; commonly combined withpodSelectorin the samefrom/toentry to mean "these specific pods, but only in namespaces with this label," rather than either alone.- An empty
podSelector: {}at the top level of the spec selects every pod in the namespace; an empty selector inside afrom/toentry means "all pods" for that source/destination.
Default behavior
With no NetworkPolicy selecting a pod at all, every ingress and egress connection to and from it is allowed, no restriction whatsoever. The moment at least one policy selects a pod and declares a policyTypes direction (say, Ingress), that direction flips to default-deny for that pod: only traffic matching an explicit rule is allowed, and everything else in that direction is dropped. This is why a common, deliberate starting point is a namespace-wide default-deny policy (a policy selecting all pods with empty ingress/egress rules) followed by narrow allow rules added on top, rather than trying to enumerate every exception against an open-by-default baseline.
Trade-offs and pitfalls
- NetworkPolicies are additive across multiple policies selecting the same pod (a union of allowed traffic, not an intersection), which means adding a second, broader policy to a namespace can unintentionally widen access that a narrower first policy had restricted.
- Egress policies frequently get overlooked because ingress is the more obvious security concern, but an over-permissive default (no egress policy at all) lets a compromised pod exfiltrate data or reach internal services it has no business reaching; DNS resolution in particular is easy to break by an egress default-deny policy that forgets to allow port 53 to the cluster's DNS service.
- Because enforcement lives in the CNI, NetworkPolicy behavior (which selector combinations are supported, whether egress is supported at all, performance under many rules) varies by CNI choice; a policy that works correctly in one cluster is not guaranteed to behave identically after a CNI migration.
Explain how online PVC resizing works in Kubernetes. Describe the necessary conditions (StorageClass allowVolumeExpansion, filesystem support, kubelet/node support) and the steps you would take to resize a PVC from 100Gi to 200Gi with minimal downtime.
Sample Answer
Direct answer
Online PersistentVolumeClaim (PVC) expansion needs three things to line up: the StorageClass must set allowVolumeExpansion: true, the CSI (Container Storage Interface) driver must implement the ControllerExpandVolume and NodeExpandVolume calls, and the filesystem plus kubelet must support growing in place (resize2fs for ext4, xfs_growfs for xfs). When all three hold, resizing from 100Gi to 200Gi is a one-line patch to the PVC with no pod restart. When the node-side piece is missing, the pod needs a restart to pick up the new size, which is the only source of downtime in the whole process.
Structured elaboration
Preconditions
$ kubectl get storageclass fast-ssd -o jsonpath='{.allowVolumeExpansion}'
true
If this is empty or false, expansion is rejected at the PVC level before anything else matters. Patching allowVolumeExpansion onto an existing StorageClass is safe; it only affects future resize requests, not past provisioning.
Steps to go from 100Gi to 200Gi
$ kubectl patch pvc data-pvc -p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
persistentvolumeclaim/data-pvc patched
Kubernetes then drives two calls against the CSI driver in sequence:
ControllerExpandVolume, issued by the external-resizer sidecar, grows the underlying block device (or cloud volume) and updates the PersistentVolume's recorded capacity.NodeExpandVolume, issued by the kubelet on whichever node has the volume mounted, grows the filesystem to fill the new device size.
Watch the PVC's events to see this happen:
$ kubectl describe pvc data-pvc
Events:
Type Reason Message
Normal Resizing External resizer is resizing volume
Normal FileSystemResizeSuccessful MountVolume.NodeExpandVolume succeeded for volume "pvc-..."
If the CSI driver only supports offline expansion, the event sequence instead pauses at FileSystemResizePending. The fix is to let the pod restart (respecting any PodDisruptionBudget) so the kubelet can run NodeExpandVolume against the volume once it is unmounted and remounted.
Minimizing downtime for the offline case
For a single-replica stateful workload the restart is unavoidable but brief. For a replicated one, cordon and evict one replica at a time so the others keep serving, exactly the pattern a PodDisruptionBudget protects during any voluntary disruption, resize included.
Worked example
A 100Gi PVC backed by a CSI driver that supports online expansion is patched to 200Gi. ControllerExpandVolume grows the cloud volume to 200Gi and the PersistentVolume object's capacity updates to match; NodeExpandVolume then runs resize2fs (or the xfs equivalent) against the already-mounted filesystem, and kubectl describe pvc shows FileSystemResizeSuccessful without the pod ever restarting. If the same driver only supported offline expansion, the sequence would stop at FileSystemResizePending until the pod is deleted and rescheduled, at which point the kubelet completes the resize during the new mount.
Trade-offs and pitfalls
- PVCs can only be resized upward; shrinking is not supported the same way.
- Not every CSI driver implements online (in-place) expansion. Check the specific driver's documentation rather than assuming; "supports expansion" and "supports expansion without a restart" are different claims.
- Resize during low traffic and keep a snapshot beforehand. The resize itself does not touch existing data, but any manual filesystem operation carries risk if interrupted.
Design an etcd backup and restore strategy that meets RPO = 5 minutes and RTO ≤ 30 minutes for a cluster controlling 1000 nodes. Include snapshot frequency, WAL archival, offsite storage, automation, validation testing, encryption, and practical considerations for large snapshot sizes.
Sample Answer
Meet RPO = 5 minutes and RTO <= 30 minutes with two layers: a snapshot cadence tight enough to bound data loss, and a rehearsed, automated restore pipeline that removes human decision-making from the critical path. etcd (the strongly-consistent key-value store that is the single source of truth for all cluster state, including every object the API server serves) has exactly one supported backup primitive: a full point-in-time snapshot via etcdctl snapshot save. There is no supported mechanism to continuously ship etcd's internal write-ahead log (WAL, the durability journal etcd itself uses before committing to its storage engine) to an external archive and replay it to an arbitrary revision the way you would with a database that ships transaction logs (for example Postgres WAL archiving). Treating WAL files as an externally replayable artifact is a common design mistake; the design below does not rely on it.
Component design
| Concern | Approach | Why |
|---|---|---|
| Snapshot cadence | Full etcdctl snapshot save every 2 minutes | Bounds RPO to the cadence itself; 2 minutes gives headroom under the 5-minute target for scheduling jitter |
| Sub-cadence data loss | Frequent storage-level (block/volume) snapshots of the etcd data directory on a schedule between application snapshots, or a warm-standby etcd learner member | Closes the gap between snapshot ticks without inventing WAL-replay tooling that does not exist |
| Offsite durability | Upload each snapshot to object storage in a second region immediately after it completes, with server-side encryption and versioning enabled | Survives a full primary-region loss |
| Automation | A CronJob or systemd timer runs snapshot, checksum, encrypt, upload, and prune as one pipeline; the restore path is an equally scripted, idempotent runbook, not ad hoc commands | Removes operator error from the critical 30-minute window |
| Validation | Nightly automated restore into a scratch environment plus a periodic full DR game day | An untested backup is a hypothesis, not a plan |
| Encryption | TLS in transit for both the etcd peer/client traffic and the upload; server-side encryption at rest in object storage, with client-side envelope encryption via a key management service for the most sensitive clusters | Snapshots contain every Secret's ciphertext-at-rest plus the encryption-at-rest key references; treat them as highly sensitive |
| Large snapshot size (1000 nodes) | Compact and defragment before snapshotting; compress with a fast codec; chunked/multipart upload | A 1000-node cluster with dense workloads can push the etcd dataset into multiple gigabytes, and etcd's own guidance is to keep the working set well under its default 2 GiB backend quota (raisable, but performance degrades well before you would want to push it much past single-digit gigabytes) |
flowchart LR
A[etcdctl snapshot save] --> B[checksum + zstd compress]
B --> C[encrypt: KMS envelope]
C --> D[multipart upload to primary-region bucket]
D --> E[cross-region replication]
F[nightly restore job] --> G[scratch cluster]
E --> F
G --> H[consistency + smoke test]
H --> I[alert on failure]
Compaction and defragmentation (day-2 maintenance that feeds the backup design)
etcd's storage engine is an MVCC (multi-version concurrency control) store: every write creates a new revision, and old revisions accumulate until removed. Two distinct operations matter here and the basis design blurred them:
- Compaction (
etcdctl compactor--auto-compaction-retention) discards historical revisions older than a retention point. It shrinks the logical keyspace but does not shrink the on-disk file. - Defragmentation (
etcdctl defrag) reclaims that freed space at the storage-engine level. It must be run one member at a time, off-peak, because a member briefly stops serving requests while it defrags; running it cluster-wide at once risks a quorum-visible latency spike or, in the worst case, a temporary loss of quorum if it overlaps with another disruption.
Run compaction continuously (auto-compaction) and defragmentation on a rotating per-member schedule shortly before the snapshot window, so the snapshot reflects a compacted, defragmented (and therefore smaller and faster to transfer and restore) dataset.
Cross-version restore caveat
A snapshot embeds objects serialized at whatever API storage version was in effect when they were written. Kubernetes deprecates and eventually removes old API versions on its normal release cadence. If you restore a snapshot taken on an older Kubernetes minor version directly onto a control plane several minors ahead, objects stored under a since-removed API version may not deserialize correctly, and the standard upgrade path (one minor version at a time) does not apply retroactively to a restored snapshot. The safe sequence is: restore into a control plane running the same (or adjacent, supported) Kubernetes version as the snapshot's source, confirm the cluster is healthy, then upgrade forward normally. Do not treat "restore, then jump several versions" as equivalent to "upgrade, then restore."
The PV data etcd does not back up
etcd stores the PersistentVolume (PV) and PersistentVolumeClaim (PVC) objects (the binding metadata: which claim is bound to which volume, capacity, storage class), not the actual bytes sitting on the underlying disks. Restoring etcd alone rehydrates the metadata but not the data on the volumes; if the real volumes have moved on or been deleted since the snapshot was taken, the restored PVC objects can point at storage that no longer matches. A cluster running stateful workloads needs a coordinated backup (for example Velero with a volume-snapshot plugin) that captures PV data snapshots at a consistent point relative to the etcd snapshot, not just the etcd side of the picture.
Restore-time budget (illustrative, not a benchmark)
The 30-minute RTO is a budget you allocate across steps, not a single measured number (actual time depends on cloud provider, disk and network throughput, and snapshot size, so do not present it as a guarantee):
| Step | Illustrative budget |
|---|---|
| Detect failure, page, and confirm restore is the right call | a few minutes |
| Provision or reuse pre-warmed etcd member nodes | a few minutes if pre-warmed, much longer if built from scratch |
| Download and decompress the snapshot | scales with snapshot size and network throughput |
etcdctl snapshot restore and bring members up, verify quorum | a fixed, testable cost you measure in your own drills |
| Health-check the control plane and run smoke tests | a few minutes |
Pre-provisioning restore nodes (rather than building them from scratch during the incident) is usually the single biggest lever for hitting a 30-minute target, because it removes the least predictable step from the critical path.
Trade-offs and pitfalls
- Tighter snapshot cadence reduces RPO but increases I/O load on the leader and snapshot storage cost; 1-2 minutes is a reasonable floor for a 1000-node cluster without specialized tuning.
- A warm-standby etcd learner member (a non-voting member that replicates writes, available since etcd 3.4) can shrink the effective RPO further, but it adds an always-on member to operate and is not a substitute for offsite snapshots since it shares the same cluster's failure domain unless deliberately placed elsewhere.
- Skipping defragmentation to save time on the backup path makes every subsequent snapshot, upload, and restore slower; it is cheaper to pay that cost on a schedule than under incident pressure.
- The most common way this design fails in practice is not the backup half, it is an untested restore: teams that only test
snapshot saveand never rehearsesnapshot restoreunder time pressure regularly discover their real RTO is far higher than 30 minutes on the first real incident.
Unlock Full Question Bank
Get access to all Kubernetes Architecture, Operations, and Troubleshooting interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.