Tracks, Repositories & Costs
Before writing any infrastructure, decide where it runs, how the code is split across repositories, and how you will make sure nothing keeps costing money after you stop working. This lesson makes those three decisions.
Two tracks
| Local track (default) | Cloud track (optional) | |
|---|---|---|
| Cluster | kind (Kubernetes in Docker) or k3d (k3s in Docker) on your machine | EKS (or GKE, see the mapping in Cloud Track) |
| Created by | OpenTofu with the kind provider, or the kind CLI |
OpenTofu with the AWS provider and the community VPC and EKS modules |
| PostgreSQL | CloudNativePG operator in the cluster | Amazon RDS for PostgreSQL |
| Redis | a small Redis Deployment per environment | Amazon ElastiCache |
| Registry | a local registry container, or kind load |
GHCR or ECR |
| Ingress traffic | Gateway API with Envoy Gateway; kubectl port-forward or a local load-balancer helper |
Gateway API with a cloud load balancer |
| Cost | free (your laptop's CPU and memory) | real money per hour: see below |
Everything above the infrastructure (image, chart, GitOps repository, dashboards, alerts) is identical on both tracks. That is the point of the layering: the chart and the Argo CD Applications don't know whether the cluster is a laptop or a region.
The local track needs Docker (or Podman), kind or k3d, kubectl, helm, tofu and Go. A kind cluster running Argo CD, Prometheus and the app is comfortable with about 4 CPU cores and 8 GB of memory available to Docker; with less, leave the monitoring stack for its own section.
What the cloud track costs
Prices change and differ between regions, so this course doesn't quote numbers. Check your provider's current pricing pages and cost calculator before each cloud lesson. What you will pay for:
| Item | Charged | Notes |
|---|---|---|
| EKS control plane | per hour, per cluster | charged even with no workloads |
| Worker nodes | per instance-hour (EC2) | the biggest variable: pick small instances, 2 nodes |
| NAT gateway | per hour and per GB processed | often the surprise on the first bill; one shared NAT for a practice VPC |
| Load balancer | per hour plus capacity units | created by the Gateway controller for a LoadBalancer Service |
| RDS and ElastiCache | per instance-hour plus storage | smallest instance classes, single-AZ for practice |
| Data transfer, logs, snapshots | per GB | CloudWatch log groups and final snapshots outlive the cluster |
Three habits keep the bill small:
- Set a budget alert first. A monthly budget with an email alert at a low threshold (AWS Budgets, GCP budgets) before you create anything.
- Tear down in the same sitting. Every cloud lesson ends with a teardown step. A practice cluster left running over a weekend costs more than the rest of the course.
- Tag everything with
project = "linkly"andowner, so a cost report or a cleanup script can find leftovers.
Three repositories
| Repository | Holds | Who changes it |
|---|---|---|
acme/linkly |
Go source, tests, Dockerfile, Helm chart, CI workflow, alert rules, runbook | developers, through pull requests |
acme/linkly-deploy |
which chart and image version runs in which environment, Argo CD Applications | pull requests from people and from the CI bot |
acme/linkly-infra |
OpenTofu for the cluster and platform add-ons (local and cloud roots) | platform changes, planned in CI |
The split follows the GitOps repository layouts lesson: deployment history stays readable, and the deploy repository can have stricter review rules than the app. A single repository with three top-level folders works too for a portfolio project; keep the three concerns in separate folders either way.
The session lays out the skeleton you will fill in over the course and commits it, so later lessons have a place for every file:
for repo in linkly linkly-deploy linkly-infra; do git init -q "$repo"; done
mkdir -p linkly/.github/workflows linkly/chart/linkly/templates linkly/monitoring linkly/docs
mkdir -p linkly-deploy/apps/linkly/staging linkly-deploy/apps/linkly/production linkly-deploy/argocd linkly-deploy/platform
mkdir -p linkly-infra/local/cluster linkly-infra/local/platform linkly-infra/cloud
printf '# linkly\n\nA link shortener, shipped end to end. See docs/.\n' > linkly/README.md
printf '/linkly\n/dist/\n*.tgz\n' > linkly/.gitignore
printf '.terraform/\n*.tfstate\n*.tfstate.*\n*.tfvars\n!example.tfvars\n' > linkly-infra/.gitignore
for repo in linkly linkly-deploy linkly-infra; do
find "$repo" -type d -empty -not -path '*/.git/*' -exec touch {}/.keep \;
git -C "$repo" add . && git -C "$repo" commit -qm "Skeleton" && echo "$repo: $(git -C "$repo" log --oneline)"
done
tree --noreport -a -I '.git|.keep' linkly linkly-deploy linkly-infralinkly: e55f28d Skeleton
linkly-deploy: 87b9285 Skeleton
linkly-infra: 73d82f2 Skeleton
linkly
├── .github
│ └── workflows
├── .gitignore
├── README.md
├── chart
│ └── linkly
│ └── templates
├── docs
└── monitoring
linkly-deploy
├── apps
│ └── linkly
│ ├── production
│ └── staging
├── argocd
└── platform
linkly-infra
├── .gitignore
├── cloud
└── local
├── cluster
└── platform
Two details in the skeleton matter later. linkly-infra/.gitignore keeps state files and *.tfvars out of Git from the first commit: state can contain secrets, and real variable files often do (Terraform state). And the empty linkly/docs/ folder is where the runbook and architecture notes go; a project without them is half a portfolio piece.
Teardown, as a habit
Write the teardown down before the first apply. For the local track it is two commands; for the cloud track it is an ordered list, because some resources block the deletion of others:
# Local track
tofu -chdir=local/platform destroy
kind delete cluster --name linkly
# Cloud track: delete what Kubernetes created in AWS first, then the infrastructure
kubectl delete gateway --all -A # releases the cloud load balancer
tofu -chdir=cloud destroy
aws resourcegroupstaggingapi get-resources --tag-filters Key=project,Values=linkly \
--query 'ResourceTagMappingList[].ResourceARN' # should print []Load balancers and volumes created by controllers in the cluster are not in OpenTofu's state; destroy the cluster first and they stay behind, still billing, and can even block the VPC's deletion. That ordering problem shows up again in Deploy, Roll Back & Tear Down.
Test yourself
Which part of the system differs between the local and the cloud track?
- The Helm chart
- The Argo CD Applications
- The infrastructure layer: cluster, database and cache services
- The alert rules
Why delete Gateways (and LoadBalancer Services) before running tofu destroy on the cloud track?
- Gateways are expensive to keep in Git
- Controllers created cloud load balancers that are not in OpenTofu's state; they would be left behind and can block VPC deletion
- OpenTofu cannot delete EKS clusters
- It makes the destroy faster
Why does the infra repository ignore *.tfstate and *.tfvars from the first commit?
- They are binary files
- State and real variable files can contain secrets
- Git cannot store HCL
- OpenTofu refuses to run otherwise