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.

Cluster inspection

Inspect state, events and placement

Docker & Kubernetes

get summarizes objects; describe expands status and related events. Wide output shows additional placement/network data.

Fragment

Docker & Kubernetes · Inspect state, events and placement
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl get pods -n demo -o wide
kubectl describe pod POD_NAME -n demo
kubectl get events -n demo --sort-by=.metadata.creationTimestamp

Events are time-bounded diagnostic records, not a complete audit log.

Choose the Pod, container and attempt

Docker & Kubernetes

logs targets a container’s captured output. --previous requests the previous terminated instance when available.

Fragment

Docker & Kubernetes · Choose the Pod, container and attempt
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl logs POD_NAME -c app -n demo --tail=50
kubectl logs POD_NAME -c app -n demo --previous

A crash loop often requires previous-instance logs plus exit status/events. Logs may be rotated or absent.

Create a temporary local diagnostic tunnel

Docker & Kubernetes

port-forward connects a local port to a selected workload endpoint while the command runs.

Fragment

Docker & Kubernetes · Create a temporary local diagnostic tunnel
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl port-forward -n demo service/demo 8080:80

This is a local diagnostic path, not a production exposure or end-to-end ingress test.

Review desired-state changes

Docker & Kubernetes

diff previews the live-versus-desired change. apply submits desired configuration; controllers reconcile it asynchronously.

Fragment

Docker & Kubernetes · Review desired-state changes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl diff -f deployment.yaml -n demo
kubectl apply -f deployment.yaml -n demo

kubectl diff commonly exits 1 when differences exist. Applying successfully does not establish rollout health.

Run a diagnostic command in a chosen container

Docker & Kubernetes

-- separates kubectl options from the command. -c chooses a container in a multi-container Pod; -i/-t provide interactive input and a terminal when needed.

Fragment

Docker & Kubernetes · Run a diagnostic command in a chosen container
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl exec -n demo POD_NAME -c app -- /app --version
# If the image includes a shell:
kubectl exec -it -n demo POD_NAME -c app -- sh

Minimal images may contain neither a shell nor familiar utilities. Debug-container workflows have their own permissions and lifecycle.

Inspect a Service’s actual backends

Docker & Kubernetes

EndpointSlices describe Service backends and their conditions. Compare the Service selector, Pod labels, ports and readiness when traffic has no expected destination.

Fragment

Docker & Kubernetes · Inspect a Service’s actual backends
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl get service demo -n demo -o yaml
kubectl get pods -n demo -l app=demo --show-labels
kubectl get endpointslices -n demo \
  -l kubernetes.io/service-name=demo -o yaml

A populated EndpointSlice is one piece of evidence; routing, policies and application listeners can still fail.

Inspect resource use and restart causes

Docker & Kubernetes

top reports observed CPU/memory use when a metrics provider is installed. describe/status and previous logs provide different evidence about scheduling and container exits.

Fragment

Docker & Kubernetes · Inspect resource use and restart causes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl top pods -n demo
kubectl describe pod POD_NAME -n demo
kubectl logs POD_NAME -c app -n demo --previous

Current low usage does not prove a prior OOM did not occur. Requests, limits and measured usage are different quantities.