Kubernetes Fundamentals
Master the core concepts of Kubernetes (K8s) container orchestration and understand its architecture.What is Kubernetes?
Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.Orchestration
Manages container lifecycle, scheduling, and health
Scaling
Automatically scales apps up or down based on demand
Self-healing
Restarts failed containers, replaces and kills containers that don’t respond
Load Balancing
Distributes network traffic to maintain stability
Kubernetes Architecture
A Kubernetes cluster consists of a Control Plane and a set of Worker Nodes.Control Plane Components
The “brain” of the cluster.- API Server: The frontend for the K8s control plane. Exposes the Kubernetes API.
- etcd: Consistent and highly-available key value store for all cluster data.
- Scheduler: Watches for newly created Pods with no assigned node, and selects a node for them to run on.
- Controller Manager: Runs controller processes (e.g., Node Controller, Job Controller).
Node Components
Run on every node, maintaining running pods and providing the Kubernetes runtime environment.- Kubelet: An agent that runs on each node. It ensures that containers are running in a Pod.
- Kube-Proxy: Maintains network rules on nodes. Allows network communication to your Pods.
- Container Runtime: The software that is responsible for running containers (e.g., Docker, containerd).
Core Objects
1. Pods
The smallest deployable unit in Kubernetes.- Represents a single instance of a running process.
- Can contain one or more containers (usually one).
- Containers in a Pod share:
- Network: Same IP address and port space (can talk via
localhost). - Storage: Shared volumes.
- Network: Same IP address and port space (can talk via
2. Namespaces
Virtual clusters backed by the same physical cluster.- Used to divide cluster resources between multiple users/teams.
- Examples:
default,kube-system,dev,prod.
kubectl Basics
kubectl is the command-line tool for communicating with the Kubernetes API server.
Cluster Info & Navigation
Viewing Resources
Interacting with Pods
Creating Your First Pod
Kubernetes objects are typically defined in YAML files.Imperative (CLI)
Quick for testing, but not recommended for production.Declarative (YAML)
The “Infrastructure as Code” way.Pod Lifecycle
- Pending: Pod accepted by system, but container image not yet created.
- Running: Pod bound to a node, all containers created, at least one running.
- Succeeded: All containers terminated successfully (exit code 0).
- Failed: All containers terminated, at least one with failure.
- Unknown: State cannot be obtained.
Resource Management
Every container should have resource requests and limits defined.Requests vs Limits
| Concept | Description | Interview Insight |
|---|---|---|
| Request | Minimum resources guaranteed | Used by Scheduler to place pods |
| Limit | Maximum resources allowed | Enforced at runtime; OOMKilled if exceeded |
Quality of Service (QoS) Classes
Kubernetes assigns QoS classes based on resource settings:| QoS Class | Condition | Eviction Priority |
|---|---|---|
| Guaranteed | requests = limits (both CPU and memory) | Last to be evicted |
| Burstable | requests < limits, or only one is set | Middle priority |
| BestEffort | No requests or limits | First to be evicted |
Health Probes (Critical for Interviews!)
Probes allow Kubernetes to know when to restart or route traffic to a container.Liveness Probe
“Is the container alive?” - If it fails, the container is restarted.Readiness Probe
“Is the container ready to receive traffic?” - If it fails, the Pod is removed from Service endpoints.Startup Probe
“Has the application started?” - For slow-starting apps. Disables liveness/readiness probes until it succeeds.etcd Deep Dive
etcd is the “source of truth” for Kubernetes. Understanding it is crucial for interviews.Key Facts
- Distributed key-value store using Raft consensus
- Stores all cluster state: Pods, Services, Secrets, ConfigMaps
- Strongly consistent - reads return the most recent write
- Typically runs as a 3 or 5 node cluster (odd numbers for quorum)
Common Interview Questions
What happens if etcd goes down?
What happens if etcd goes down?
- Existing workloads continue running (kubelet manages local pods)
- No new operations possible (no scheduling, no API calls)
- Cluster is in read-only mode until etcd recovers
How is etcd backed up?
How is etcd backed up?
What is the quorum?
What is the quorum?
Quorum = (n/2) + 1. For 3 nodes, quorum is 2. If you lose quorum, etcd becomes read-only.
RBAC Basics
Role-Based Access Control (RBAC) regulates access to Kubernetes resources.Key Components
| Resource | Scope | Description |
|---|---|---|
| Role | Namespace | Defines permissions within a namespace |
| ClusterRole | Cluster-wide | Defines permissions across all namespaces |
| RoleBinding | Namespace | Binds Role to users/groups/service accounts |
| ClusterRoleBinding | Cluster-wide | Binds ClusterRole cluster-wide |
Pod Lifecycle
- Pending: Pod accepted by system, but container image not yet created.
- Running: Pod bound to a node, all containers created, at least one running.
- Succeeded: All containers terminated successfully (exit code 0).
- Failed: All containers terminated, at least one with failure.
- Unknown: State cannot be obtained.
Interview Questions & Answers
What is the difference between a Pod and a Container?
What is the difference between a Pod and a Container?
A Container is a single running process with its own filesystem and network namespace.
A Pod is a Kubernetes abstraction that can contain one or more containers that share:
- Network namespace (same IP, communicate via localhost)
- Storage volumes
- Lifecycle (created and destroyed together)
How does the Kubernetes Scheduler work?
How does the Kubernetes Scheduler work?
- Watches for unscheduled Pods (via API Server)
- Filtering: Eliminates nodes that don’t meet requirements (resources, taints, nodeSelector)
- Scoring: Ranks remaining nodes based on priorities (least utilized, affinity rules)
- Binding: Assigns Pod to the highest-scoring node
What is the difference between kubectl apply and kubectl create?
What is the difference between kubectl apply and kubectl create?
- create: Creates a resource. Fails if it already exists.
- apply: Creates or updates a resource. Idempotent. Recommended for GitOps workflows.
How does Kubernetes handle node failures?
How does Kubernetes handle node failures?
- Node Controller marks node as
NotReadyafter 40s of no heartbeat - After
pod-eviction-timeout(default 5min), pods are evicted - Deployment/ReplicaSet controllers create replacement pods on healthy nodes
What is a sidecar container?
What is a sidecar container?
A container that runs alongside the main application container in the same Pod to provide supporting functionality:
- Logging: Collects and ships logs (e.g., Fluentd sidecar)
- Service Mesh: Handles networking (e.g., Envoy proxy in Istio)
- Security: Handles TLS termination or secrets injection
Key Takeaways
- Control Plane manages the cluster; Nodes run the applications.
- Pods are the atomic unit of scheduling.
- Use Declarative (YAML) configuration for reproducibility.
- Always define resource requests and limits.
- Implement liveness and readiness probes for production workloads.
kubectl describeandkubectl logsare your best friends for debugging.
Next: Kubernetes Workloads →