lifecycle

kubectl run

Imperatively creates a single Pod running a specified image. In modern kubectl it only produces a Pod (Deployment/Job generators were removed) - use it for ad-hoc debugging containers, not durable workloads.

kubectl run NAME --image=IMAGE [--env=KEY=VAL] [--port=PORT] [--command -- CMD args...] [flags]

Common flags

Flag Purpose
--image Container image to run (required).
--rm Delete the pod on exit (combine with -it for one-shot shells).
-it Attach an interactive TTY (equivalent to -i --tty).
--restart Restart policy: Always (default), OnFailure, or Never.
--env Set an environment variable (repeatable).
--command Treat args after -- as the container command instead of args.
--dry-run none, client, or server; combine with -o yaml to scaffold a Pod manifest.
--overrides JSON string merged into the generated Pod spec for advanced fields.

Examples

kubectl run debug --rm -it --image=busybox:1.36 -- sh

Ephemeral shell in the cluster for troubleshooting.

kubectl run curl --image=curlimages/curl:8.5.0 --restart=Never -- curl -sS http://svc/api

One-shot HTTP test against an internal service.

kubectl run web --image=nginx:1.25 --port=80 --dry-run=client -o yaml > pod.yaml

Scaffold a Pod manifest without creating it.

Gotcha

run no longer creates Deployments - use kubectl create deployment for durable workloads. --rm needs -it, otherwise the pod detaches and lingers.

Related commands

← All kubectl commands · Docker vs Kubernetes