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

← All kubectl commands · Docker vs Kubernetes