Skip to content

About

End-to-end GitOps pipeline on AWS: Terraform provisions infra, Ansible bootstraps K3s, GitHub Actions builds/scans/pushes images via OIDC, and ArgoCD auto-deploys a Flask app — with Prometheus/Grafana monitoring on top.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

Repository files navigation

GitOps K3s AWS

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.

Stack

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)

Repo layout

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

Flow

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
Loading

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.

How it fits together

  1. Terraform provisions a VPC, an EC2 instance, an ECR repository, and an OIDC provider for GitHub Actions, with state stored in S3.
  2. Ansible connects to the new EC2 instance, hardens the OS, and installs K3s — after this step kubectl get nodes works from your machine.
  3. The Flask app in app/ is containerized and initially deployed manually to confirm the cluster works end to end.
  4. GitHub Actions takes over from there: on every push to main that touches app/**, it builds the image, scans it with Trivy, and pushes it to ECR — authenticating via OIDC rather than long-lived AWS keys.
  5. ArgoCD watches the helm/app-chart path in this repo and automatically syncs the cluster to match, so a git push is all it takes to deploy.
  6. 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.

Getting started

Prerequisites

  • AWS account + credentials configured locally
  • Terraform
  • Ansible
  • kubectl, helm
  • Docker

1. Provision infrastructure

cd terraform
cp terraform..tfvars.example terraform.tfvars
# fill in aws_region, environment, instance_type, and my_ip
terraform init
terraform apply

2. Bootstrap the cluster

cd ansible
ansible-playbook -i inventory playbooks/site.yml

This installs K3s on the EC2 instance. Once it finishes, copy the kubeconfig locally and confirm:

kubectl get nodes

3. Deploy ArgoCD and the app

kubectl apply -f argocd/argocd-app.yml
kubectl apply -f argocd/argocd-ingress.yml

ArgoCD will pick up helm/app-chart and deploy the Flask app into the production namespace.

4. Set up CI

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_KEY secrets (or switch fully to OIDC role assumption)
  • an ECR_REPOSITORY repository variable

From here, any push to main touching app/** builds, scans, and pushes a new image, and ArgoCD deploys it.

5. Install monitoring

helm install monitoring prometheus-community/kube-prometheus-stack -f monitoring/monitoring-value.yml

App endpoints

Route Purpose
/ Status check
/healthz Liveness/readiness probe for K3s
/version Returns the deployed app version

Notes / known TODOs

  • 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)

About

End-to-end GitOps pipeline on AWS: Terraform provisions infra, Ansible bootstraps K3s, GitHub Actions builds/scans/pushes images via OIDC, and ArgoCD auto-deploys a Flask app — with Prometheus/Grafana monitoring on top.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages