Skip to content

Phase 6 — GitOps and Automated Deployments with ArgoCD

Phase 4 left the application running on a two-node Raspberry Pi Kubernetes cluster, with Flux providing basic GitOps reconciliation and Prometheus and Grafana covering observability. Every deployment still required a manual step — either kubectl apply or flux reconcile.

Phase 5 removes that manual step entirely.

This phase implements a complete GitOps workflow — ArgoCD watching a dedicated Git branch, Kustomize overlays managing environment-specific configuration, and a five-job GitHub Actions pipeline that runs tests, scans for vulnerabilities, builds multi-platform images, updates manifests with the new image tag, and lets ArgoCD handle the rest. A commit to main is now the only action required to deploy a new version.


Phase 4 used Flux. Phase 5 switches to ArgoCD. The reasoning is deliberate.

Flux is lighter — 160MB versus ArgoCD’s 500MB — which is why it was the right choice for Phase 4 on constrained Raspberry Pi hardware. But ArgoCD has a web UI that makes GitOps concepts visible and interactive. For a learning and portfolio context, being able to watch ArgoCD detect drift in real time, show the exact diff between Git and the cluster, and display a resource tree of every tracked object is worth the additional memory footprint.

Both tools do the same job. The difference is what is visible while they do it.


The first design decision was where GitOps configuration lives. The answer was a dedicated gitops branch in the same repository, with all manifests under a gitops-safe/ directory.

The name gitops-safe/ is deliberate. It signals that this is the ArgoCD-managed copy of the manifests — separate from the k8s/ directory used for manual kubectl apply. When something breaks, it is immediately clear which set of files ArgoCD is reading and which files are the manual fallback.

The directory follows the standard Kustomize base/overlay pattern:

gitops-safe/
├── base/ # Working manifests — copied from k8s/, not modified
├── overlays/dev/ # Dev overlay — adds GitOps labels
└── overlays/prod/ # Production overlay — placeholder for future use

The base layer lists the nine application manifest files. The dev overlay references the base and adds four standard app.kubernetes.io/ labels to every resource. Those labels are how ArgoCD tracks which Kubernetes objects belong to which Application.

There is an important subtlety here. Kustomize’s commonLabels does not only add labels to metadata.labels — it also injects them into spec.selector.matchLabels on Deployments and spec.selector on Services. Kubernetes selector fields on Deployments are immutable after the resource is created. Applying commonLabels to a running Deployment fails if the selectors do not match. The solution was to delete the existing Deployments before the first ArgoCD sync so that ArgoCD could recreate them with the correct selectors from scratch.

This is not a workaround. It is the correct sequence for introducing GitOps to an existing application.


Two ArgoCD resources were created: an AppProject and an Application.

The AppProject is the security boundary. It specifies exactly which Git repository ArgoCD is allowed to read from, which namespace it is allowed to deploy to, and which Kubernetes resource types it is permitted to create or modify. Any operation outside those boundaries is refused — regardless of what the Application requests. It is the kind of restriction that is easy to skip in a homelab and critical to implement correctly in production.

The Application is the resource that tells ArgoCD what to watch and where to deploy it. It points to the gitops branch, the gitops-safe/overlays/dev path, and the humor-game namespace. ArgoCD runs kubectl kustomize on that path, compares the output against the live cluster state, and syncs the difference.

After the first sync, ArgoCD was tracking 19 resources across ConfigMaps, PersistentVolumeClaims, Services, and Deployments. That count is a useful checkpoint — if a resource is missing from kustomization.yaml, the count drops and the gap is immediately visible.


The most immediately useful ArgoCD capability is drift detection. It runs continuously — comparing the live cluster state against the desired state in Git on every poll cycle.

To demonstrate it, a Deployment was manually scaled:

Terminal window
kubectl scale deployment backend --replicas=3 -n humor-game

Within three minutes ArgoCD flagged the application as OutOfSync. The UI showed the exact diff — replicas: 3 in the cluster versus replicas: 1 in Git. The application was still running correctly. The sync status reflected a configuration difference, not a failure.

This is the practical value of GitOps. In a team environment, that OutOfSync status is a signal that something changed outside the agreed process. The correct response is either to sync — reverting the manual change — or to update the Git manifest to reflect the intended state. Either way, Git remains the record of what the cluster is supposed to look like.

Self-healing takes drift detection one step further — ArgoCD automatically reverts the cluster to the Git-defined state without waiting for a manual sync. It is enabled with a single field:

syncPolicy:
automated:
prune: false
selfHeal: true

In a learning environment this is safe to enable. In production, the decision depends on whether automatic reversion is appropriate for each specific workload.


The GitHub Actions pipeline has five jobs. Tests and security scanning run in parallel. Images only build on main and develop — feature branches run tests only. Manifest updates only run on main.

Job 1 — Test: Checks out the application source repository and runs npm test on the Node.js backend. The frontend is vanilla JavaScript served by Nginx — no build step, no test framework. The backend test script was a placeholder echo command for most of the project; Phase 7 replaced it with a real Jest test suite for the first time.

Job 2 — Security scan: Trivy scans the DevOps repository file system for known CVEs in application dependencies, restricted to CRITICAL and HIGH severity findings. Results are informational — the job does not fail on findings, keeping the pipeline from blocking on low-risk advisories while keeping security visibility in the workflow log.

Job 3 — Build and push: Docker images are built for both linux/amd64 and linux/arm64 using QEMU emulation on the GitHub-hosted runner, and pushed to Docker Hub. Each image receives two tags — :latest and :main-<shortsha>. The main-shortsha tag is the important one. It is immutable and uniquely identifies the exact source commit that produced the image. The SHA is derived from the application source repository’s HEAD commit — not the DevOps repository — because the tag identifies the application code version being shipped.

Job 4 — Update GitOps manifests: This is the link between CI/CD and GitOps. After images are pushed, yq updates the image tag field in gitops-safe/base/backend-deployment.yaml and gitops-safe/base/frontend-deployment.yaml, then commits and pushes the change back to the repository. yq was chosen over sed because it is a proper YAML processor — it updates only the target field without reformatting the rest of the file. sed on YAML is fragile.

Job 5 — Notify: Reports the final pipeline status. In this homelab setup it prints to the workflow log. In production this would send a Slack or webhook notification.

ArgoCD detects the manifest commit within its polling interval and syncs the new images to the cluster. No manual steps. No kubectl apply. The only human action required was pushing the code.


Seven issues were found and resolved during implementation. None were visible until the pipeline ran against the real cluster.

The gitops branch needed to be checked out explicitly. Job 4 of the pipeline checks out humor-memory-game-kubernetes to update the image tags. The default checkout goes to the repository’s default branch — main. ArgoCD watches the gitops branch. Pushing the updated manifests to main had no effect on the cluster. Adding ref: gitops to the checkout step fixed it.

The ARM64 image architecture problem. The GitHub-hosted runner is AMD64. The Raspberry Pi nodes are ARM64. Without an explicit platforms field, docker/build-push-action builds for the runner’s native architecture only — producing AMD64-only images. When Kubernetes scheduled those pods onto the Pi nodes, every pod entered ImagePullBackOff. The fix was adding docker/setup-qemu-action@v3 before the Buildx step and setting platforms: linux/amd64,linux/arm64 on both build steps. The same multi-platform pattern used in Phase 3 for manual builds.

The yq install approach. The original pipeline installed yq at runtime via wget from the GitHub releases page. A review of the runner environment confirmed that yq has been pre-installed on GitHub-hosted Ubuntu runners since 2021. The install step was removed entirely — calling the pre-installed binary directly is simpler and eliminates the version mismatch risk that comes with fetching a binary at runtime.

The SOURCE_PAT and GITOPS_PAT secrets were both mapped to the same token. Two fine-grained Personal Access Tokens were created — Token A with read access to humor-memory-game and Token B with read/write access to humor-memory-game-kubernetes. During secret configuration both secrets were accidentally set to the value of Token B. Job 1 failed immediately with Bad credentials when checking out the source repository. Correcting the mapping — SOURCE_PAT to Token A, GITOPS_PAT to Token B — resolved it.

The frontend Dockerfile needed nginx.conf and start.sh from the DevOps repository. The frontend build context is the humor-memory-game/frontend/ directory from the source repository. The Dockerfile references nginx.conf and start.sh via COPY instructions — but those files live in humor-memory-game-devops/docker/frontend/, not in the frontend source. The build failed with “file not found.” A copy step before the Docker build — copying both files from the DevOps repository into the frontend build context — resolved it.

The nginx.conf and start.sh copy path in the pipeline was wrong. After adding the copy step the path referenced frontend/scripts/game.js — the wrong directory. This surfaced during the BUG-001 fix cycle when the same path confusion appeared in the source repository. Both the pipeline copy step and the subsequent documentation were corrected to use frontend/src/scripts/game.js.

[skip ci] in the GitOps manifest commit message is not optional. Job 4 commits updated image tags to the gitops branch and pushes. Without [skip ci] in the commit message, that push re-triggers the pipeline — which builds again, commits again, and loops indefinitely. The tag is present in the commit message template and must not be removed or modified.


Five documents cover the complete Phase 5 implementation:

Document Purpose
GITOPS_INSTALL.md ArgoCD installation — namespace, install, wait, password retrieval, port-forward, UI access
GITOPS_SETUP.md Repository structure — Kustomize base and overlays, AppProject and Application YAML with annotated and production copies
GITOPS_DEPLOY.md Apply ArgoCD configuration, first sync, verify tracked resources, drift detection, self-healing
CICD_PIPELINE.md GitHub Actions pipeline — five jobs explained individually with annotated and production copies
GITOPS_TROUBLESHOOTING.md Fault diagnosis and resolution across ArgoCD, Kustomize, CI/CD, and application issues

  • Production-grade GitOps workflow with ArgoCD — AppProject security boundaries, Application lifecycle management, drift detection, and self-healing
  • Kustomize base/overlay pattern for environment separation without manifest duplication
  • Five-job GitHub Actions CI/CD pipeline with parallel execution, conditional job logic, and automated manifest updates
  • Image tag strategy — immutable branch-shortsha tags for deployments, understood distinction between mutable and immutable tags
  • Security scanning integrated into the delivery pipeline with Trivy and GitHub Security tab
  • Complete audit trail — every deployment traceable to a Git commit, every rollback achievable with git revert
  • Troubleshooting methodology — symptom, root cause, diagnosis commands, fix, lesson learned

Phase 7 covers what happened when the pipeline was used for the first time to deploy a real code change — and what it revealed about the cluster that had been running for weeks. The database was completely empty. The game had never successfully started on Kubernetes. Phase 7 is the diagnosis and resolution story.

← Phase 5 — Observability with Prometheus and Grafana on Kubernetes

→ Phase 7 — End-to-End Validation and What the Pipeline Revealed


Repository: sjchristie/humor-memory-game-kubernetes Documentation: docs/