Deploying via Git

Deploying BookNest Through Git, Not kubectl

Now a change to production is a commit. Argo CD 126 refreshes every 120 seconds plus up to 60 of jitter, and its repo server caches a branch's commit for 3 minutes, so without a GitHub 29 webhook a push can take six minutes:

A commit becomes a deploymentYAML
J='{.status.operationState.syncResult.revision} {.status.operationState.phase}'
synced() { until kubectl -n argocd get app booknest -o jsonpath="$J" \
  | grep -q "^$(git rev-parse HEAD) Succeeded"; do sleep 2; done; }
yq -i '.replicas = [{"name": "web", "count": 3}]' production/kustomization.yaml
git commit -qam "Run three front-end replicas" && git push -q
S0=$(date +%s); synced
echo "synced $(git rev-parse --short HEAD) after $(( $(date +%s) - S0 )) s"
kubectl rollout status deployment/web >/dev/null && kubectl get deployment web
Output
synced e8f24c5 after 223 s
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    3/3     3            3           137m

With selfHeal, a hand edit of production is put back at once:

Drift is undoneShell
kubectl scale deployment web --replicas=1
S0=$(date +%s)
until [ "$(kubectl get deployment web -o jsonpath='{.spec.replicas}')" = 3 ]; do sleep 1; done
echo "back to 3 replicas after $(( $(date +%s) - S0 )) s"
Output
deployment.apps/web scaled
back to 3 replicas after 2 s

A rollback is a revert commit:

Rolling back with git revertShell
git revert --no-edit HEAD >/dev/null && git push -q
S0=$(date +%s); synced
echo "synced $(git rev-parse --short HEAD) after $(( $(date +%s) - S0 )) s"
kubectl get deployment web -o jsonpath='{.spec.replicas}{"\n"}'
git log --oneline
Output
synced 8becece after 319 s
2
8becece Revert "Run three front-end replicas"
e8f24c5 Run three front-end replicas
9eec17d Add the Argo CD Application
00d69a7 BookNest production, from the Kustomize overlay

Argo CD's own argocd app rollback works only with automated sync off, since the next poll would restore HEAD; in GitOps the revert is the rollback.

The booknest Application's sync status after the revert: Synced to the revert commit, Healthy
The booknest Application's sync status after the revert: Synced to the revert commit, Healthy