Kubernetes Pods
Pod YAML - the smallest deployable unit in Kubernetes. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Search across all documentation pages
Pod YAML - the smallest deployable unit in Kubernetes. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Minimal Pod with one container.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx
image: nginx:alpine
# kubectl get pod webPin tags or digests.
spec:
containers:
- name: api
image: ghcr.io/acme/api:1.2.3
# imagePullPolicy defaults depend on tagPlain env vars on a container.
env:
- name: PORT
value: "3000"
# process sees PORT=3000Declare container ports (documentation + Service targeting).
ports:
- name: http
containerPort: 8080
# does not publish on the node by itselfAlways for Deployments; OnFailure/Never for Jobs.
restartPolicy: Always
# kubelet restarts crashed containersOverride image ENTRYPOINT/CMD.
command: ["node"]
args: ["server.js"]
# runs node server.jsAlways/IfNotPresent/Never.
imagePullPolicy: IfNotPresent
# skip pull when local tag existsSelect pods with labels.
metadata:
labels:
app: web
# selector matchLabels: app=webSimple node placement constraint.
nodeSelector:
disk: ssd
# schedules only on labeled nodesPod identity for API access.
serviceAccountName: api-sa
# uses that SA tokenRun as non-root example.
securityContext:
runAsNonRoot: true
runAsUser: 1000
# container uid 1000Run setup before app containers.
initContainers:
- name: migrate
image: migrate:1
command: ["migrate", "up"]
# app starts after init succeedsDebug sidecars sharing PID namespace.
shareProcessNamespace: true
# sidecar can see app PIDsPod uses host network namespace - avoid unless needed.
hostNetwork: true
# binds ports on the node networkSeconds to wait on delete before SIGKILL.
terminationGracePeriodSeconds: 30
# 30s graceful shutdown windowStack versions: Kubernetes 1.36.2 · Docker Engine 29.6.1 · Helm 3 · Compose v2 · containerd via CRI
Reviewed by Chris St. John·Last updated Jul 18, 2026