Kubectl Apply and Delete
Declarative GitOps basics: apply, diff, prune, and delete.
- kubectl apply
- kubectl diff
- kustomize
- gitops
- kubectl delete
Kubectl Apply and Delete
Declarative GitOps basics: apply, diff, prune, and delete.
Commands
| Command | What it does |
|---|---|
kubectl apply -f app.yaml | Create or update from a manifest |
kubectl diff -f app.yaml | Preview changes before applying |
kubectl apply -k ./overlays/prod | Kustomize overlay deploy |
kubectl delete -f app.yaml | Remove everything a file defines |
kubectl apply --prune -l app=shop -f ./manifests | Delete stale labeled objects |
Example
kubectl diff -f manifests/
kubectl apply -f manifests/
kubectl get all -l app=shop
FAQ
apply vs create?
apply is declarative and repeatable (stores last-applied state); create fails if the object exists.
Should I kubectl edit in prod?
Only for emergencies — always commit the fix to git so GitOps controllers do not revert it.
คำถามที่พบบ่อย
apply vs create?
apply is declarative and repeatable (stores last-applied state); create fails if the object exists.
Should I kubectl edit in prod?
Only for emergencies — always commit the fix to git so GitOps controllers do not revert it.
Kubernetes
Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
Kubectl Pods
Inspect pods, describe failures, and get a shell inside.
Kubectl Deployments
Create, update, and inspect Deployments that own your pods.
Kubectl Services
Expose pods stably with ClusterIP, NodePort, and LoadBalancer.