Reference

Docker & Kubernetes

Read image builds, container commands, Compose files and Kubernetes workload configuration.

Scope and conventions

Docker CLI/Dockerfile, Docker Compose and Kubernetes native YAML/kubectl. These are complementary tools, not interchangeable editions. Commands assume your own disposable local environment; image names, cluster objects and paths are illustrative. Nothing runs from this guide.

Kubernetes workloads

Pod, Deployment and replica

Docker & Kubernetes

A Pod groups containers sharing a network namespace and declared volumes. A Deployment manages ReplicaSets that maintain replicated Pods.

Fragment

Docker & Kubernetes · Pod, Deployment and replica
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
spec:
  replicas: 2
  selector:
    matchLabels: { app: demo }
  template:
    metadata:
      labels: { app: demo }
    spec:
      containers:
        - name: app
          image: example/demo:release
          ports:
            - containerPort: 8080

This is an illustrative manifest; supply an image your cluster can pull and run. containerPort does not create external exposure.

Match labels to the intended Pods

Docker & Kubernetes

Labels identify objects; selectors choose sets of them. A Deployment selector must match its template labels and is immutable after creation.

Fragment

Docker & Kubernetes · Match labels to the intended Pods
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
metadata:
  labels:
    app: demo
    component: api

A Service selector with a typo can produce no endpoints even while Pods are running.

Service port versus targetPort

Docker & Kubernetes

A Service provides a stable endpoint for selected backends. port is the Service port; targetPort is the Pod-side port.

Fragment

Docker & Kubernetes · Service port versus targetPort
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
apiVersion: v1
kind: Service
metadata:
  name: demo
spec:
  selector: { app: demo }
  ports:
    - port: 80
      targetPort: 8080

ClusterIP is the default internal Service type. NodePort, LoadBalancer and Ingress solve different exposure needs.

Choose a workload by lifecycle

Docker & Kubernetes

Deployment: replaceable service replicas. StatefulSet: stable per-Pod identity/storage relationships. DaemonSet: a Pod on each selected node. Job: run to completion. CronJob: schedule Jobs.

Fragment

Docker & Kubernetes · Choose a workload by lifecycle
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl get deployments,statefulsets,daemonsets,jobs,cronjobs

A scheduled Job can run more than once; external effects still need an appropriate retry/idempotency design.