This is Part 1 of the six-part build in the Sprint 6 project overview. By the end you have an AWS account laid out for the project, a private network, an EKS cluster whose nodes are managed by Karpenter, a managed PostgreSQL database and a cache, keys and DNS, Argo CD syncing from Git, Crossplane ready to create tenant buckets, Cilium enforcing network policy, two Capsule tenants that cannot see each other, and Istio mutual TLS between services.
Where this part fits. This part builds the foundation and tenancy (marked Part 1 on the overall diagram). Open the zoomable Sprint 6 architecture or read the Overview.
What this is and is not. This is engineering guidance, not legal or financial advice. It is a reference blueprint: the intended flow and the wiring between the tools. Versions, chart keys, module inputs and field names change between releases, so each section gives a check to confirm them on your version. If you hit a bug or a mismatch, use the “Suggest a correction” link on this page.
What you build, and in what order
One image, the layers of this part. Open the zoomable diagram, or download it as SVG or PNG.
The work splits by who owns the resource:
- OpenTofu owns the base: state bucket, VPC, EKS, the Karpenter node role and queue, RDS, ElastiCache, KMS, Route 53, CloudFront and ECR. These rarely change and the cluster needs them to exist.
- Argo CD and Crossplane own what the platform asks for: Karpenter pools, Capsule tenants, policies, the mesh, and the S3 buckets each tenant gets. They are Kubernetes objects reviewed in Git.
- Prerequisites and account
- Repository and state bucket
- The foundation stack (network, EKS, data, edge)
- Karpenter pools
- Argo CD
- Crossplane
- Cilium
- Capsule tenants
- Istio mutual TLS
- Troubleshooting, cost, cleanup, checklist
1. Prerequisites and account
You need an AWS account with an administrator role for the person building, and a workstation with Git, the AWS CLI v2, kubectl, Helm, OpenTofu 1.10 or newer (the S3 backend lockfile needs it) and jq. Part 2 adds Python.
Choose the Region and confirm the services exist there before creating anything:
export AWS_REGION=ap-south-1
aws sts get-caller-identity
aws eks describe-cluster-versions --region $AWS_REGION --query 'clusterVersions[?status==`STANDARD_SUPPORT`].clusterVersion'
aws rds describe-orderable-db-instance-options --engine postgres --db-instance-class db.m7g.large \
--region $AWS_REGION --query 'OrderableDBInstanceOptions[].EngineVersion' --output text | tr '\t' '\n' | sort -V | tail -3
aws elasticache describe-cache-engine-versions --engine redis --region $AWS_REGION --query 'CacheEngineVersions[-1].EngineVersion'
Pick the newest Kubernetes version in standard support (an older minor drops into the extended-support price, see the cost note) and a current PostgreSQL minor. Write both down; the stack takes them as variables. Hyderabad (ap-south-2) is only a backup target in Part 6, so nothing is created there now.
2. Repository and state bucket
mkdir erp-platform && cd erp-platform && git init
mkdir -p infra/foundation gitops/platform gitops/apps tenancy mesh crossplane ops docs
export STATE_BUCKET=erp-tfstate-$(aws sts get-caller-identity --query Account --output text)-$AWS_REGION
aws s3api create-bucket --bucket $STATE_BUCKET --region $AWS_REGION \
--create-bucket-configuration LocationConstraint=$AWS_REGION
aws s3api put-bucket-versioning --bucket $STATE_BUCKET --versioning-configuration Status=Enabled
aws s3api put-public-access-block --bucket $STATE_BUCKET \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
The state bucket is created by hand once, because OpenTofu cannot create the place it stores its own state. Check: aws s3api get-bucket-versioning --bucket $STATE_BUCKET prints Enabled.
3. The foundation stack
3.1 Providers and backend
# infra/foundation/main.tf
terraform {
required_version = ">= 1.10"
backend "s3" {} # values come from -backend-config at init
required_providers {
aws = { source = "hashicorp/aws", version = "~> 6.0" }
}
}
provider "aws" { region = var.region }
variable "region" { type = string }
variable "k8s_version" { type = string }
variable "pg_version" { type = string }
variable "name" { type = string, default = "erp" }
variable "my_ip_cidr" { type = string } # who may reach the public API endpoint
cd infra/foundation
tofu init -backend-config="bucket=$STATE_BUCKET" -backend-config="key=foundation.tfstate" \
-backend-config="region=$AWS_REGION" -backend-config="use_lockfile=true"
3.2 Keys and network
One customer-managed KMS key encrypts RDS, ElastiCache and the cluster secrets. The VPC uses the community module so the three-zone layout is short:
resource "aws_kms_key" "platform" {
description = "${var.name} platform key"
enable_key_rotation = true
deletion_window_in_days = 7
}
data "aws_availability_zones" "az" { state = "available" }
locals { azs = slice(data.aws_availability_zones.az.names, 0, 3) }
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 6.0" # confirm the current major
name = var.name
cidr = "10.20.0.0/16"
azs = local.azs
private_subnets = ["10.20.0.0/20", "10.20.16.0/20", "10.20.32.0/20"]
public_subnets = ["10.20.200.0/24", "10.20.201.0/24", "10.20.202.0/24"]
enable_nat_gateway = true
single_nat_gateway = true # lab: one NAT; production: one per zone
private_subnet_tags = { "karpenter.sh/discovery" = var.name, "kubernetes.io/role/internal-elb" = 1 }
public_subnet_tags = { "kubernetes.io/role/elb" = 1 }
}
# Gateway endpoint keeps S3 traffic off the NAT gateway.
resource "aws_vpc_endpoint" "s3" {
vpc_id = module.vpc.vpc_id
service_name = "com.amazonaws.${var.region}.s3"
route_table_ids = module.vpc.private_route_table_ids
}
NAT gateways cost per hour and per gigabyte (see the cost note), so the lab uses one and the S3 gateway endpoint, which has no hourly charge. ECR image pulls also go through NAT unless you add interface endpoints; Part 6 revisits this when it reads the bill.
3.3 EKS with Pod Identity and the Karpenter prerequisites
The community EKS module has a karpenter submodule that creates the node role, the controller’s permissions and the interruption queue.
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 21.0" # confirm the current major and input names
name = var.name
kubernetes_version = var.k8s_version
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
endpoint_public_access = true
endpoint_public_access_cidrs = [var.my_ip_cidr]
enable_cluster_creator_admin_permissions = true
addons = {
vpc-cni = { before_compute = true }
coredns = {}
kube-proxy = {}
eks-pod-identity-agent = { before_compute = true }
}
# A small managed group runs Karpenter and the platform controllers; Karpenter manages everything else.
eks_managed_node_groups = {
system = {
instance_types = ["m7g.large"]
ami_type = "AL2023_ARM_64_STANDARD"
min_size = 2, max_size = 3, desired_size = 2
taints = { critical = { key = "CriticalAddonsOnly", effect = "NO_SCHEDULE" } }
}
}
node_security_group_tags = { "karpenter.sh/discovery" = var.name }
}
module "karpenter" {
source = "terraform-aws-modules/eks/aws//modules/karpenter"
version = "~> 21.0"
cluster_name = module.eks.cluster_name
create_pod_identity_association = true
node_iam_role_additional_policies = { ssm = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" }
}
Two choices to note. The system group is Arm (Graviton) and tainted, so only add-ons that tolerate it run there; the ERP workloads land on Karpenter nodes. And the cluster endpoint is public but limited to your address, which is a lab convenience; a production cluster would use a private endpoint and a VPN or bastion.
3.4 RDS PostgreSQL and ElastiCache
resource "aws_security_group" "data" {
name = "${var.name}-data"
vpc_id = module.vpc.vpc_id
ingress { from_port = 5432, to_port = 5432, protocol = "tcp", security_groups = [module.eks.node_security_group_id] }
ingress { from_port = 6379, to_port = 6379, protocol = "tcp", security_groups = [module.eks.node_security_group_id] }
}
resource "aws_db_subnet_group" "erp" { name = var.name, subnet_ids = module.vpc.private_subnets }
resource "aws_db_instance" "erp" {
identifier = "${var.name}-pg"
engine = "postgres"
engine_version = var.pg_version
instance_class = "db.m7g.large"
allocated_storage = 50
storage_encrypted = true
kms_key_id = aws_kms_key.platform.arn
db_name = "erp"
username = "erp_admin"
manage_master_user_password = true # the password lives in Secrets Manager, never in state
db_subnet_group_name = aws_db_subnet_group.erp.name
vpc_security_group_ids = [aws_security_group.data.id]
publicly_accessible = false
multi_az = false # lab; production: true
backup_retention_period = 7
skip_final_snapshot = true # lab only
deletion_protection = false # lab only
}
resource "aws_elasticache_subnet_group" "erp" { name = var.name, subnet_ids = module.vpc.private_subnets }
resource "aws_elasticache_replication_group" "erp" {
replication_group_id = "${var.name}-cache"
description = "ERP sessions and caches"
engine = "redis" # confirm whether you prefer Valkey on your provider version
node_type = "cache.t4g.small"
num_cache_clusters = 1
subnet_group_name = aws_elasticache_subnet_group.erp.name
security_group_ids = [aws_security_group.data.id]
at_rest_encryption_enabled = true
transit_encryption_enabled = true
kms_key_id = aws_kms_key.platform.arn
}
3.5 DNS, edge and registry
resource "aws_ecr_repository" "erp" {
for_each = toset(["erp-api", "erp-web", "copilot-agent", "mcp-tools"])
name = "${var.name}/${each.key}"
image_tag_mutability = "IMMUTABLE"
image_scanning_configuration { scan_on_push = true }
}
# Route 53 zone and CloudFront distribution are added once the gateway has a load balancer
# in Part 5; this part only creates the zone, so DNS delegation can start early.
resource "aws_route53_zone" "erp" { count = var.domain == "" ? 0 : 1, name = var.domain }
variable "domain" { type = string, default = "" }
No domain? Skip the zone. Part 5 documents the no-domain path through the load balancer name and its limits for TLS and OIDC.
3.6 Apply and connect
tofu plan -out plan.tfplan -var region=$AWS_REGION -var k8s_version=<from step 1> -var pg_version=<from step 1> -var my_ip_cidr=$(curl -s https://checkip.amazonaws.com)/32
tofu apply plan.tfplan
aws eks update-kubeconfig --name erp --region $AWS_REGION
kubectl get nodes
Check: two system nodes are Ready; aws rds describe-db-instances --query 'DBInstances[].[DBInstanceStatus,StorageEncrypted,PubliclyAccessible]' prints available, True, False; the cache group is available.
4. Karpenter pools
Argo CD (next section) will own these objects; apply them by hand now to prove the node path, then move them into gitops/platform/karpenter/.
helm upgrade --install karpenter oci://public.ecr.aws/karpenter/karpenter --namespace kube-system \
--version <current> --set settings.clusterName=erp --set settings.interruptionQueue=<queue from tofu output> \
--set tolerations[0].key=CriticalAddonsOnly --set tolerations[0].operator=Exists
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata: { name: default }
spec:
role: <node role name from tofu output>
amiSelectorTerms: [{ alias: al2023@latest }] # pin a version in production
subnetSelectorTerms: [{ tags: { karpenter.sh/discovery: erp } }]
securityGroupSelectorTerms: [{ tags: { karpenter.sh/discovery: erp } }]
---
apiVersion: karpenter.sh/v1
kind: NodePool
metadata: { name: general }
spec:
template:
spec:
nodeClassRef: { group: karpenter.k8s.aws, kind: EC2NodeClass, name: default }
requirements:
- { key: karpenter.sh/capacity-type, operator: In, values: ["on-demand"] }
- { key: kubernetes.io/arch, operator: In, values: ["arm64", "amd64"] }
- { key: karpenter.k8s.aws/instance-category, operator: In, values: ["m", "c"] }
limits: { cpu: "64" }
disruption: { consolidationPolicy: WhenEmptyOrUnderutilized, consolidateAfter: 1m }
The GPU pool is not created now; Part 3 adds it only for the hours it is needed. Check: run kubectl create deployment probe --image=public.ecr.aws/docker/library/nginx --replicas=3 with a resource request of 1 CPU each, then kubectl get nodeclaims; a node appears within a few minutes. Delete the probe and the node disappears after consolidation.
5. Argo CD
helm repo add argo https://argoproj.github.io/argo-helm && helm repo update
helm upgrade --install argocd argo/argo-cd -n argocd --create-namespace --set global.tolerations[0].key=CriticalAddonsOnly --set global.tolerations[0].operator=Exists
kubectl -n argocd rollout status deploy/argocd-server
Create the root application that watches gitops/platform:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: root, namespace: argocd }
spec:
project: default
source: { repoURL: https://github.com/<you>/erp-platform.git, targetRevision: main, path: gitops/platform, directory: { recurse: true } }
destination: { server: https://kubernetes.default.svc, namespace: argocd }
syncPolicy: { automated: { prune: true, selfHeal: true } }
Check: kubectl -n argocd get application root shows Synced and Healthy. From here, every platform object in this part goes into gitops/platform/ and is applied by Argo CD rather than by hand.
6. Crossplane
Install Crossplane through an Argo CD application, then the S3 provider, using Pod Identity for credentials rather than static keys.
# gitops/platform/crossplane.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: crossplane, namespace: argocd }
spec:
project: default
source: { repoURL: https://charts.crossplane.io/stable, chart: crossplane, targetRevision: <current> }
destination: { server: https://kubernetes.default.svc, namespace: crossplane-system }
syncPolicy: { automated: { prune: true, selfHeal: true }, syncOptions: [CreateNamespace=true] }
# gitops/platform/provider-s3.yaml
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata: { name: provider-aws-s3 }
spec: { package: xpkg.upbound.io/upbound/provider-aws-s3:<current> }
Give the provider’s service account an IAM role through a Pod Identity association limited to the tenant bucket prefix, created in OpenTofu next to the cluster. Check: kubectl get providers shows INSTALLED True and HEALTHY True. Tenant buckets themselves are requested by claims in Part 2, when there are documents to store.
7. Cilium
On EKS the simplest route that keeps the VPC CNI is chaining mode, where Cilium adds policy and visibility on top. Confirm the values against the Cilium documentation for EKS chaining for your version before applying.
helm upgrade --install cilium cilium/cilium -n kube-system --version <current> \
--set cni.chainingMode=aws-cni --set cni.exclusive=false \
--set routingMode=native --set enableIPv4Masquerade=false \
--set tolerations[0].operator=Exists
kubectl -n kube-system rollout status ds/cilium
A default-deny policy per tenant namespace comes from Capsule in the next section. Check: kubectl -n kube-system exec ds/cilium -- cilium status reports the agent healthy, and after section 8 a pod in one tenant cannot reach a pod in another.
8. Capsule tenants
helm repo add projectcapsule https://projectcapsule.github.io/charts
helm upgrade --install capsule projectcapsule/capsule -n capsule-system --create-namespace
Two tenants, each with an owner, a namespace quota, a resource quota and a default network policy that allows only its own namespaces:
apiVersion: capsule.clastix.io/v1beta2
kind: Tenant
metadata: { name: acme }
spec:
owners: [{ name: acme-admins, kind: Group }]
namespaceOptions: { quota: 5 }
resourceQuotas:
scope: Tenant
items:
- hard: { limits.cpu: "16", limits.memory: 32Gi, pods: "100" }
networkPolicies:
items:
- policyTypes: [Ingress, Egress]
podSelector: {}
ingress: [{ from: [{ namespaceSelector: { matchLabels: { capsule.clastix.io/tenant: acme } } }] }]
egress:
- to: [{ namespaceSelector: { matchLabels: { capsule.clastix.io/tenant: acme } } }]
- to: [{ namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: kube-system } } }]
ports: [{ port: 53, protocol: UDP }]
Create a second tenant globex the same way. Check the field names with kubectl explain tenant.spec on your Capsule version; the tenant API has moved between releases.
Check: as the acme group, create a namespace, then try to create one more than the quota (it is refused), and run a pod that tries to reach a pod in a globex namespace (it times out). Cilium and Capsule together produce that result: Capsule writes the policy, Cilium enforces it.
9. Istio mutual TLS
helm repo add istio https://istio-release.storage.googleapis.com/charts
helm upgrade --install istio-base istio/base -n istio-system --create-namespace
helm upgrade --install istiod istio/istiod -n istio-system --wait
Label each tenant namespace for injection through the Capsule tenant (namespaceOptions.additionalMetadata.labels: { istio-injection: enabled }), then require mutual TLS mesh-wide:
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata: { name: default, namespace: istio-system }
spec: { mtls: { mode: STRICT } }
Check: deploy two small test pods in one tenant; istioctl proxy-status lists both as synced; a plain-text curl from a pod without a sidecar to a meshed pod is refused; a call between the two meshed pods succeeds.
10. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
tofu init cannot reach the backend |
Wrong Region or bucket name | Re-run with the values from section 2 |
| Lock error on apply | A killed run left a lock | tofu force-unlock <ID> after confirming nobody else is running |
Nodes not Ready |
VPC CNI or Pod Identity add-on not up before nodes | Keep before_compute = true; check kubectl -n kube-system get pods |
kubectl times out |
Your IP changed | Update my_ip_cidr and apply |
| Karpenter pods Pending | They need to tolerate the system taint | Add the CriticalAddonsOnly toleration (section 4) |
No NodeClaim appears |
Subnet or security group tags missing | Both need karpenter.sh/discovery: erp |
NodeClaim stuck Unknown |
Node role missing the access entry or policies | Use the role the karpenter module created |
| RDS unreachable from a pod | Wrong security group | Only the node security group may reach 5432; test from a pod, not your laptop |
Provider never Healthy |
Package version not found or no AWS permission | Pin a listed version; check the Pod Identity association’s service account name |
| Cilium pods crash after install | Chaining values wrong for your version | Compare with the Cilium EKS chaining guide; keep cni.exclusive=false |
| Tenant pods cannot resolve DNS | Egress policy blocks CoreDNS | Keep the port 53 rule to kube-system |
| Pods fail after enabling STRICT mTLS | Namespace not injected, so no sidecar | Label the namespace and restart the pods |
Cost note
Read on 3 December 2026, US East list prices (Mumbai prices were not read): the EKS control plane is $0.10 per cluster hour, about $73 a month, and $0.60 an hour if the Kubernetes version falls into extended support. A NAT gateway is $0.045 per hour plus $0.045 per GB processed. RDS db.m7g.large for PostgreSQL is about $123 a month on demand; that figure is from a third-party aggregator, not an AWS page. ElastiCache, EC2 nodes, KMS, Route 53 and CloudFront prices were not read, so they are not itemised. For a three-day build, the system group and a few Karpenter nodes are the main compute line; leave Part 1 running between parts and tear it down only at the end of Part 6.
Cleanup
Delete in reverse. Remove the Capsule tenants and the Karpenter pools first, so no nodes are left behind, then the Argo CD applications, then the foundation:
kubectl delete tenant acme globex
kubectl delete nodepool --all && kubectl delete ec2nodeclass --all
kubectl -n argocd delete application root crossplane
cd infra/foundation && tofu destroy -var ...
aws s3 rb s3://$STATE_BUCKET --force # last; empty object versions first if needed
The lab RDS has no final snapshot and no deletion protection; with production settings, change both before destroying. The KMS key is scheduled for deletion, not deleted at once.
Design notes and version checks
- Nothing here was run on an AWS account. The code follows the documentation I read for the modules and charts named; module majors, input names and Helm values are the likeliest places to differ. Each section gives a check; use “Suggest a correction” if one fails.
- Module inputs. The community VPC and EKS modules renamed several inputs across majors (for example the cluster name and Kubernetes version inputs). Confirm with
tofu validateand the module’s current README. - Cilium on EKS. Chaining mode keeps the VPC CNI; running Cilium as the only CNI is a different install. Confirm the chosen mode before enabling Cilium features that need it.
- Capsule fields.
networkPolicies,resourceQuotasandnamespaceOptionsare written from memory of the v1beta2 API; confirm withkubectl explain. - Istio and Cilium together. Both enforce traffic rules; the design uses Cilium for network policy and Istio for identity and encryption between services. Confirm sidecar or ambient mode against your Istio version.
- RDS and the graph store. Apache AGE on RDS was not confirmed, so the graph runs on CloudNativePG in Part 2 or Part 4; pgvector is expected on RDS.
- Single NAT and single-zone database. Chosen to keep the lab cheap, not for production.
Setup checklist
- 1. Account and tools: done when
aws sts get-caller-identityshows the lab account and the CLIs print versions. - 2. State bucket: done when versioning is
Enabledand the public access block is on. - 3. Network and EKS: done when two system nodes are
Ready. - 4. Data services: done when RDS is
available, encrypted and not public, and the cache group isavailable. - 5. Karpenter: done when a probe workload causes a
NodeClaimand the node disappears after the probe is deleted. - 6. Argo CD: done when
rootis Synced and Healthy. - 7. Crossplane: done when the S3 provider is Healthy.
- 8. Cilium: done when the agent reports healthy on every node.
- 9. Tenants: done when
acmeandglobexexist, the quota refuses an extra namespace and cross-tenant traffic times out. - 10. Mesh: done when STRICT mutual TLS refuses plain traffic and allows meshed traffic.
Tools used
OpenTofu, Crossplane, Argo CD, Karpenter, Capsule, Cilium, Istio, Kubernetes, Helm.
What comes next
Part 2 builds the data the ERP lives on: SchemaHero tables in the RDS database, Kafka on MSK with Apicurio contracts, Cadence workflows, the ClickHouse feed and CubeFS documents, and the seed generator that fills the tenants. Back to the Overview.


