An end-to-end GitOps pipeline that provisions a K3s Kubernetes cluster on AWS, deploys a small Flask app to it, and ships changes automatically via CI + ArgoCD — with monitoring and alerting on top.
Push to main → image is built, scanned, and pushed to ECR → ArgoCD syncs the new version to the cluster. No manual kubectl apply.
| Layer | Tooling |
|---|---|
| Infrastructure | Terraform (VPC, EC2, security groups, ECR, OIDC) |
| Cluster bootstrap | Ansible + K3s |
| Application | Flask + Gunicorn, containerized with Docker |
| CI | GitHub Actions (build → Trivy scan → push to ECR via OIDC) |
| Delivery | ArgoCD (Helm chart in helm/app-chart) |
| Observability | Prometheus, Grafana, Alertmanager (via Helm) |
terraform/ AWS infra: VPC, EC2 instance, ECR repo, OIDC provider, state in S3
ansible/ OS hardening + K3s install on the EC2 instance
app/ Flask app, Dockerfile, requirements
helm/app-chart/ Helm chart for the app, deployed by ArgoCD
argocd/ ArgoCD Application + Ingress manifests
monitoring/ Helm values for the Prometheus/Grafana/Alertmanager stack
.github/workflows/ CI pipeline (build, scan, push)
overview/ Project notes and part-by-part breakdown
flowchart TB
subgraph INFRA["1 · Infrastructure — Terraform"]
direction LR
T1[VPC + Subnets] --> T2[Security Groups]
T2 --> T3[EC2 Instance]
T1 --> T4[ECR Repository]
T1 --> T5[OIDC Provider<br/>for GitHub Actions]
end
subgraph BOOTSTRAP["2 · Cluster Bootstrap — Ansible"]
direction LR
A1[Harden OS] --> A2[Install K3s]
A2 --> A3[kubectl get nodes ✓]
end
subgraph CI["3 · CI Pipeline — GitHub Actions"]
direction LR
C1[git push to main<br/>app/**] --> C2[Assume AWS role<br/>via OIDC]
C2 --> C3[Build Docker image]
C3 --> C4[Trivy vulnerability scan]
C4 --> C5[Push image to ECR<br/>tag: git SHA + latest]
end
subgraph CD["4 · GitOps Delivery — ArgoCD"]
direction LR
D1[ArgoCD watches<br/>helm/app-chart] --> D2[Detects new image tag]
D2 --> D3[Auto-sync + self-heal]
end
subgraph RUNTIME["5 · Running on K3s"]
direction LR
R1[Flask App<br/>Gunicorn, 2 workers] --- R2["/healthz probe"]
R1 --- R3["/version endpoint"]
R4[Prometheus] --> R5[Grafana Dashboards]
R4 --> R6[Alertmanager]
end
INFRA --> BOOTSTRAP
BOOTSTRAP --> RUNTIME
T4 -.image storage.-> C5
T5 -.auth.-> C2
CI --> CD
CD -->|deploys to<br/>production namespace| RUNTIME
RUNTIME -.scrapes metrics.-> R4
Reading it: infrastructure and cluster bootstrap (top) happen once to stand up the cluster. From then on, every git push to main triggers the CI pipeline, which builds, scans, and pushes a new image to ECR; ArgoCD picks up the change and deploys it — no manual kubectl apply needed. Prometheus/Grafana/Alertmanager run alongside the app for observability.
- Terraform provisions a VPC, an EC2 instance, an ECR repository, and an OIDC provider for GitHub Actions, with state stored in S3.
- Ansible connects to the new EC2 instance, hardens the OS, and installs K3s — after this step
kubectl get nodesworks from your machine. - The Flask app in
app/is containerized and initially deployed manually to confirm the cluster works end to end. - GitHub Actions takes over from there: on every push to
mainthat touchesapp/**, it builds the image, scans it with Trivy, and pushes it to ECR — authenticating via OIDC rather than long-lived AWS keys. - ArgoCD watches the
helm/app-chartpath in this repo and automatically syncs the cluster to match, so agit pushis all it takes to deploy. - Monitoring (Prometheus, Grafana, Alertmanager) is installed via Helm on top of the cluster for metrics, dashboards, and alerting.
See overview/project-parts-over-view.md for the full part-by-part build plan this project follows.
- AWS account + credentials configured locally
- Terraform
- Ansible
- kubectl, helm
- Docker
cd terraform
cp terraform..tfvars.example terraform.tfvars
# fill in aws_region, environment, instance_type, and my_ip
terraform init
terraform applycd ansible
ansible-playbook -i inventory playbooks/site.ymlThis installs K3s on the EC2 instance. Once it finishes, copy the kubeconfig locally and confirm:
kubectl get nodeskubectl apply -f argocd/argocd-app.yml
kubectl apply -f argocd/argocd-ingress.ymlArgoCD will pick up helm/app-chart and deploy the Flask app into the production namespace.
Configure the following in the GitHub repo settings so .github/workflows/ci.yml can authenticate via OIDC and push to ECR:
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEYsecrets (or switch fully to OIDC role assumption)- an
ECR_REPOSITORYrepository variable
From here, any push to main touching app/** builds, scans, and pushes a new image, and ArgoCD deploys it.
helm install monitoring prometheus-community/kube-prometheus-stack -f monitoring/monitoring-value.yml| Route | Purpose |
|---|---|
/ |
Status check |
/healthz |
Liveness/readiness probe for K3s |
/version |
Returns the deployed app version |
- ECR pull secret currently expires and needs periodic renewal
- kubectl/kubeconfig setup isn't yet automated via Ansible
- No Terraform state locking configured yet (single-user project for now)