apply

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 apply -f FILENAME [-k DIRECTORY] [flags]

Common flags

Flag Purpose
-f, --filename Manifest file, directory, or URL (repeatable).
-k, --kustomize Apply a kustomization directory instead of raw YAML.
-R, --recursive Recurse into directories referenced by -f.
--dry-run none, client, or server; server does full admission without persisting.
--server-side Use server-side apply with field ownership tracking.
--force-conflicts Force take ownership of fields during server-side apply.
--prune Delete previously applied resources no longer in the input set.
-l, --selector Restrict prune/apply to resources matching a label selector.

Examples

kubectl apply -f deploy.yaml

Create or update the resources defined in a manifest.

kubectl apply -k ./overlays/prod

Apply a Kustomize overlay.

kubectl apply -f . -R --dry-run=server

Validate a whole tree of manifests through the API server without persisting.

kubectl apply --server-side --force-conflicts -f deploy.yaml

Take field ownership when migrating to SSA.

Gotcha

apply on an object created with create/kubectl edit has no last-applied annotation and may print a warning; server-side apply avoids that footgun. --prune is powerful and can delete more than you expect - always test with --dry-run=server first.

Related commands

← All kubectl commands · Docker vs Kubernetes