LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

kubectl-run

creates and runs pods

TLDR

Run pod
$ kubectl run [pod-name] --image=[nginx]
copy
Run interactive pod
$ kubectl run [pod-name] --image=[busybox] -it --rm -- [/bin/sh]
copy
Run with port
$ kubectl run [pod-name] --image=[nginx] --port=[80]
copy
Run with env vars
$ kubectl run [pod-name] --image=[nginx] --env="[KEY=value]"
copy
Dry run output
$ kubectl run [pod-name] --image=[nginx] --dry-run=client -o yaml
copy
Run with command
$ kubectl run [pod-name] --image=[busybox] -- [echo hello]
copy

SYNOPSIS

kubectl run [options] name --image=image

DESCRIPTION

kubectl run creates and starts a single pod in the cluster from a specified container image. It is designed for quick, ad-hoc pod creation and is commonly used for debugging, running one-off tasks, and testing container images without writing a full manifest file.The command supports interactive mode with `-it` for attaching a terminal session directly to the container, which is useful for launching temporary troubleshooting pods with tools like busybox or curl. Combined with `--rm`, the pod is automatically deleted when the session ends. The `--dry-run=client -o yaml` pattern is frequently used to generate a pod manifest template that can be customized and applied separately.In earlier Kubernetes versions, `kubectl run` could create deployments and other resource types, but it now exclusively creates standalone pods. For production workloads, use deployments, statefulsets, or jobs instead to get replication, rolling updates, and self-healing capabilities.

PARAMETERS

NAME

Pod name.
--image IMAGE
Container image.
-it
Interactive TTY.
--rm
Delete pod on exit.
--port PORT
Container port.
--env VAR=VALUE
Environment variable.
--dry-run MODE
Don't create resource.
--help
Display help information.

CAVEATS

Subcommand of kubectl. Creates only pods now. Use deployments for production.

HISTORY

kubectl run provides quick pod creation for Kubernetes testing and debugging.

SEE ALSO

Copied to clipboard
Kai