Kubernetes Cheatsheet
Kubernetes Basics
Use this Kubernetes reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Core Concepts
Kubernetes (k8s) orchestrates containerized workloads across a cluster of machines.
| Term | What it is |
|---|---|
| Node | A machine (VM or bare metal) in the cluster |
| Pod | Smallest deployable unit; one or more containers sharing a network/storage |
| Deployment | Manages replicated Pods; handles rollouts and rollbacks |
| Service | Stable network endpoint in front of a set of Pods |
| Namespace | Virtual cluster; isolates resources by team/environment |
| ConfigMap | Non-secret key-value config injected into Pods |
| Secret | Base64-encoded sensitive config (passwords, tokens) |
| PersistentVolume | Cluster-level storage resource |
| Ingress | HTTP/HTTPS routing rules into the cluster |
| StatefulSet | Like Deployment but for stateful apps (stable identity, ordered rollout) |
| DaemonSet | Runs one Pod per Node (logging agents, node monitors) |
| Job / CronJob | Run-to-completion tasks / scheduled tasks |
Control Plane vs. Data Plane
Control Plane Data Plane (Worker Nodes) ───────────────────── ────────────────────────── kube-apiserver ◄──REST──► kubelet (runs Pods) etcd (state) kube-proxy (iptables / IPVS) kube-scheduler container runtime (containerd) kube-controller-manager
API Versions
| Kind | API Group | apiVersion |
|---|---|---|
| Pod, Service, ConfigMap, Secret | core | v1 |
| Deployment, ReplicaSet, DaemonSet, StatefulSet | apps | apps/v1 |
| Ingress | networking.k8s.io | networking.k8s.io/v1 |
| HorizontalPodAutoscaler | autoscaling | autoscaling/v2 |
| CronJob | batch | batch/v1 |
| NetworkPolicy | networking.k8s.io | networking.k8s.io/v1 |
Minimal Manifest Skeleton
Every Kubernetes manifest shares the same four top-level fields:
apiVersion: <group>/<version> # e.g. apps/v1
kind: <Kind> # e.g. Deployment
metadata:
name: my-resource
namespace: default # omit to use current context namespace
labels:
app: my-app
spec:
# kind-specific specLabels and Selectors
Labels are arbitrary key/value pairs; selectors filter on them.
# on the resource
metadata:
labels:
app: api
env: prod
version: "2.1"# filter with kubectl kubectl get pods -l app=api kubectl get pods -l app=api,env=prod kubectl get pods -l 'env in (prod,staging)' kubectl get pods -l 'version notin (1.0)'
Annotations
Non-identifying metadata (larger values, tool hints, build info):
metadata:
annotations:
kubernetes.io/change-cause: "bump image to v2.1"
prometheus.io/scrape: "true"
prometheus.io/port: "9090"Resource Requests and Limits
Set on every container — prevents noisy-neighbor issues and enables scheduling.
resources:
requests:
cpu: "250m" # 0.25 core
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"Rule of thumb: set
requests= typical usage,limits= spike ceiling. CPU is throttled at the limit; memory OOM-kills the container.
Quality of Service Classes
| QoS Class | Condition |
|---|---|
| Guaranteed | requests == limits for every container |
| Burstable | requests < limits for at least one container |
| BestEffort | No requests or limits set |
Eviction order under memory pressure: BestEffort → Burstable → Guaranteed.
Context and Cluster Setup
kubectl config get-contexts # list all contexts kubectl config current-context # show active context kubectl config use-context my-cluster # switch context kubectl config set-context --current --namespace=staging # set default namespace