Skip to main content
⚡ OpenDevDocs
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.yaml

2. 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.yaml

4. Dry Run Validation Without Modifying Cluster

kubectl apply -f deployment.yaml --dry-run=server

Common Options

OptionShorthandDescription
--filename-fPath to a file, directory, or URL containing YAML manifests.
--recursive-RRecursively process all directory subfolders.
--dry-runSimulate request (client or server).
--pruneAutomatically delete obsolete resources omitted from manifest directory.

On this page