Kubernetes Fundamentals
Kubernetes (K8s) is an open-source container orchestration platform originally designed by Google and now maintained by the CNCF. It automates deploying, scaling, and managing containerized applications.
What Problem Does Kubernetes Solve?
Running containers manually works for small setups, but at scale you need:
- Self-healing — restart failed containers automatically
- Horizontal scaling — add/remove replicas based on load
- Rolling updates — deploy new versions with zero downtime
- Service discovery — containers find each other by name, not IP
The Kubernetes Architecture
A Kubernetes cluster has two types of nodes:
Control Plane
| Component | Role |
|---|---|
kube-apiserver | The REST API gateway — all interactions go through it |
etcd | Distributed key-value store for all cluster state |
kube-scheduler | Picks which node a new Pod should run on |
kube-controller-manager | Runs reconciliation loops (ReplicaSet, Node, etc.) |
cloud-controller-manager | Bridges to cloud-provider APIs |
Worker Nodes
| Component | Role |
|---|---|
kubelet | Agent that ensures containers in Pods are running |
kube-proxy | Maintains network rules for Service routing |
| Container runtime | Runs containers (containerd, CRI-O) |
The Pod: Kubernetes' Atomic Unit
A Pod is the smallest deployable unit. It wraps one or more containers that:
- Share the same network namespace (same IP, ports)
- Share the same storage volumes
- Are always co-located on the same node
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
Key insight: You rarely create Pods directly. Instead, you use higher-level objects (Deployments, StatefulSets) that manage Pod lifecycle for you.
Namespaces
Namespaces provide logical isolation within a cluster:
kubectl get namespaces
# default, kube-system, kube-public, kube-node-lease
All user workloads go in default unless specified. kube-system holds cluster components.
Labels and Selectors
Labels are key/value pairs attached to objects. Selectors filter objects by labels — this is how Services find Pods, and how ReplicaSets know which Pods they own.
metadata:
labels:
app: frontend
version: v2
Key kubectl Commands
kubectl get pods # list pods in default namespace
kubectl get pods -n kube-system # list pods in kube-system
kubectl describe pod <name> # detailed info + events
kubectl logs <pod-name> # container logs
kubectl exec -it <pod-name> -- bash # shell into container
kubectl apply -f manifest.yaml # apply a manifest
kubectl delete pod <name> # delete a pod
Summary
- Kubernetes manages containerized workloads at scale
- The control plane stores desired state; nodes reconcile actual state
- Pods are the atomic unit; containers inside share network and storage
- Labels + selectors are the glue connecting objects together