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
kubectl create
Imperatively creates a resource from a file or from built-in generators (deployment, configmap, secret, job, etc.). Unlike apply, it fails if the resource already exists and does not record a last-applied annotation.
kubectl exec
Executes a command inside a running container. Use -it for an interactive TTY shell; omit them for a one-shot command whose stdout you want to capture for scripts.
kubectl apply
Declaratively creates or updates resources from a manifest file, directory, URL, or kustomization. Tracks the last-applied configuration so subsequent applies compute a three-way merge patch rather than replacing the object.
kubectl delete
Deletes one or more resources by name, label, or manifest. Supports graceful termination, forced eviction of stuck pods, and cascading deletion of owned objects.
kubectl rollout
Manages the deployment lifecycle of Deployments, StatefulSets, and DaemonSets. Subcommands cover watching progress, rolling back to a revision, restarting all pods, and pausing/resuming controller reconciliation.