Apply a Kubernetes manifest to create or update resources.
medium risk
kubectl diff -f manifest.yamlSee exactly what would change.kubectl apply -f manifest.yaml --dry-run=serverValidate against the API server and admission webhooks.kubectl apply declaratively applies resource manifests from files or directories. It creates resources if they don't exist, and updates them if they do — using server-side merge. Always dry-run first in production with --dry-run=server.
| Flag | Meaning |
|---|---|
-f --filename | File, directory, or URL |
-R --recursive | Process directories recursively |
--dry-run | client or server — preview without applying |
--validate | Validate manifest before applying |
--force | Force apply by deleting and recreating |
kubectl apply -f deployment.yamlApply a single manifest · explain & risk-check →kubectl apply -f ./manifests/ -RApply all manifests in a directory · explain & risk-check →kubectl apply -f deployment.yaml --dry-run=serverServer-side dry run (validates against API) · explain & risk-check →kubectl apply -k ./overlays/productionApply Kustomize overlay · explain & risk-check →Always use `--dry-run=server` not `--dry-run=client` — server-side dry run runs full validation including admission webhooks, catching errors that client-side validation misses.
Reference text is hand-written and may be incomplete — check man kubectl for your version. Test destructive commands on a non-production system first.