Kubernetes Cheatsheet

Kubernetes Basics

Use this Kubernetes reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

Core Concepts

Kubernetes (k8s) orchestrates containerized workloads across a cluster of machines.

TermWhat it is
NodeA machine (VM or bare metal) in the cluster
PodSmallest deployable unit; one or more containers sharing a network/storage
DeploymentManages replicated Pods; handles rollouts and rollbacks
ServiceStable network endpoint in front of a set of Pods
NamespaceVirtual cluster; isolates resources by team/environment
ConfigMapNon-secret key-value config injected into Pods
SecretBase64-encoded sensitive config (passwords, tokens)
PersistentVolumeCluster-level storage resource
IngressHTTP/HTTPS routing rules into the cluster
StatefulSetLike Deployment but for stateful apps (stable identity, ordered rollout)
DaemonSetRuns one Pod per Node (logging agents, node monitors)
Job / CronJobRun-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

KindAPI GroupapiVersion
Pod, Service, ConfigMap, Secretcorev1
Deployment, ReplicaSet, DaemonSet, StatefulSetappsapps/v1
Ingressnetworking.k8s.ionetworking.k8s.io/v1
HorizontalPodAutoscalerautoscalingautoscaling/v2
CronJobbatchbatch/v1
NetworkPolicynetworking.k8s.ionetworking.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 spec

Labels 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 ClassCondition
Guaranteedrequests == limits for every container
Burstablerequests < limits for at least one container
BestEffortNo 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