Kubernetes Commands
devopskubernetesReferenceBeginner
kubectl apply
Apply declarative configuration changes to Kubernetes resources from YAML manifest files or stdin.
Verified: 2026-10-01
Tested on:kubernetes 1.31
Platforms:
all
#kubernetes#kubectl#apply#yaml#declarative
Command
kubectl apply -f deployment.yaml
Short Description
kubectl apply manages applications through declarative configuration files, creating new resources or updating existing resources in place.
Syntax
kubectl apply -f <filename_or_directory> [FLAGS]Examples
1. Apply Single Manifest File
kubectl apply -f ./k8s/deployment.yaml2. Recursively Apply All YAML Files in a Directory
kubectl apply -R -f ./k8s/3. Apply Configuration from URL
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml4. Dry Run Validation Without Modifying Cluster
kubectl apply -f deployment.yaml --dry-run=serverCommon Options
| Option | Shorthand | Description |
|---|---|---|
--filename | -f | Path to a file, directory, or URL containing YAML manifests. |
--recursive | -R | Recursively process all directory subfolders. |
--dry-run | Simulate request (client or server). | |
--prune | Automatically delete obsolete resources omitted from manifest directory. |