Kubernetes YAML Manifests

Working with YAML files

Apply Resources

kubectl apply -f file.yaml # create/update from file
kubectl apply -f directory/ # apply all files in directory
kubectl apply -f url # apply from URL

Delete Resources

kubectl delete -f file.yaml # delete from file
kubectl delete -f directory/ # delete all in directory

Dry Run

kubectl apply -f file.yaml --dry-run=client # client-side validation
kubectl apply -f file.yaml --dry-run=server # server-side validation

Generate YAML

kubectl create deployment nginx --image=nginx --dry-run=client -o yaml # generate deployment YAML
kubectl run nginx --image=nginx --dry-run=client -o yaml # generate pod YAML

Diff and Validate

kubectl diff -f file.yaml # show differences
kubectl apply -f file.yaml --validate=true # validate before apply

Export Resources

kubectl get deployment nginx -o yaml > deployment.yaml # export to YAML
kubectl get pod nginx -o json > pod.json # export to JSON