Chapter 1 · Practice 4 of 5
Keep manifests in version control and apply them declaratively
Why it matters
Changes made with kubectl edit or kubectl scale on a live cluster are invisible to review and vanish the next time someone applies the files. The configuration guide says never to apply manifests directly from your desktop: keep them in version control so you can roll back, compare changes and recreate the setup.
A workable flow:
- Keep manifests, Helm charts or Kustomize overlays in Git next to the app or in a deploy repository.
- Review changes through pull requests like any other code.
- Apply from CI or a GitOps controller such as Argo CD or Flux, not from laptops.
- Run
kubectl diff -f(or your tool's diff) in the pull request so reviewers see what will change on the cluster.
Group related objects in one file when they belong together (a Deployment and its Service), and write YAML rather than JSON, as the configuration guide suggests, because it is easier to read and review.
Example
# In CI, on every pull request
kubectl diff -f k8s/ --server-side
# On merge to main
kubectl apply -f k8s/ --server-side --field-manager=ci