Skip to content
Latchkey

kubectl create: Command Reference for CI/CD

Create a brand-new resource imperatively, or scaffold manifest YAML.

kubectl create makes a new resource and errors if it already exists, which makes it the non-idempotent counterpart to apply. Its subcommands are also the fastest way to generate correct YAML to commit. This reference covers the flags and the safe CI patterns.

Common flags and usage

  • -f, --filename: create from a manifest (fails on AlreadyExists)
  • create deployment|job|namespace: build a resource from flags
  • --dry-run=client -o yaml: print the manifest instead of creating it
  • --from=cronjob/<name>: create a one-off Job from a CronJob
  • --save-config: store last-applied so future apply merges cleanly

Example

shell
# Scaffold YAML to commit
kubectl create deployment web --image=web:${GIT_SHA} \
  --dry-run=client -o yaml > k8s/web.yaml

# Idempotent create-then-apply in a re-runnable job
kubectl create namespace ci-${BUILD_ID} \
  --dry-run=client -o yaml | kubectl apply -f -

In CI

create is not idempotent, so a retried pipeline that already created an object fails with AlreadyExists. Pipe create through apply (create ... --dry-run=client -o yaml | kubectl apply -f -) to get the generator ergonomics with declarative idempotency.

Key takeaways

  • create fails if the object exists; apply patches it instead.
  • --dry-run=client -o yaml turns create into a manifest generator.
  • For re-runnable CI, pipe create output into apply for idempotency.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →