apply
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 create (-f FILENAME | TYPE NAME [options]) [flags] Common flags
| Flag | Purpose |
|---|---|
| -f, --filename | Create from a manifest file, directory, or URL. |
| --dry-run | none, client, or server; combine with -o yaml to scaffold manifests. |
| -o, --output | Output format after creation (yaml, json, name). |
| --save-config | Store the resource config in an annotation so future apply works cleanly. |
| -n, --namespace | Target namespace. |
Examples
kubectl create deployment web --image=nginx:1.25 --replicas=3 Imperative Deployment from a generator.
kubectl create configmap app-config --from-file=./config/ ConfigMap from every file in a directory.
kubectl create secret generic db --from-literal=password=s3cret Opaque Secret from literal key/value.
kubectl create job backup --from=cronjob/nightly-backup Trigger a one-off Job from an existing CronJob.
Gotcha
create is imperative and errors on re-run; use apply for idempotent GitOps workflows. Use --dry-run=client -o yaml as a quick manifest generator.
Related commands
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 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 replace
Replaces a resource with the complete definition from a file, overwriting the entire spec. With --force it deletes and recreates the resource, which is useful for immutable fields.
kubectl patch
Applies a partial update to a resource using strategic-merge, JSON-merge, or JSON-patch semantics. It is the surgical tool for changing a single field without rewriting the whole manifest.
kubectl edit
Fetches a live resource, opens it in your $EDITOR, and applies the diff on save. Convenient for one-off tweaks; not recommended for production changes that should live in Git.