{
  "schema_version": 1,
  "kind": "article",
  "title": "Building a Kubernetes platform with Terraform modules",
  "description": "A guide to reusable modules for Kubernetes autoscaling, networking, secrets, deployment tools, and monitoring.",
  "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules",
  "markdown_url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules.md",
  "json_url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules.json",
  "language": "en",
  "author": {
    "type": "Organization",
    "name": "CloudOn",
    "url": "https://cloudon-one.com/"
  },
  "rights_url": "https://cloudon-one.com/terms",
  "indexable": true,
  "headings": [
    {
      "level": 2,
      "text": "Why Use These Modules",
      "id": "why-use-these-modules",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#why-use-these-modules"
    },
    {
      "level": 2,
      "text": "Core Modules at a Glance",
      "id": "core-modules-at-a-glance",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#core-modules-at-a-glance"
    },
    {
      "level": 3,
      "text": "Core Infrastructure",
      "id": "core-infrastructure",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#core-infrastructure"
    },
    {
      "level": 3,
      "text": "Service Mesh and Networking",
      "id": "service-mesh-and-networking",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#service-mesh-and-networking"
    },
    {
      "level": 3,
      "text": "Observability",
      "id": "observability",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#observability"
    },
    {
      "level": 3,
      "text": "Platform Tools",
      "id": "platform-tools",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#platform-tools"
    },
    {
      "level": 2,
      "text": "Architecture Overview",
      "id": "architecture-overview",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#architecture-overview"
    },
    {
      "level": 2,
      "text": "Getting Started",
      "id": "getting-started",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#getting-started"
    },
    {
      "level": 3,
      "text": "1. Clone the Repository",
      "id": "1-clone-the-repository",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#1-clone-the-repository"
    },
    {
      "level": 3,
      "text": "2. Pick Your Modules",
      "id": "2-pick-your-modules",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#2-pick-your-modules"
    },
    {
      "level": 3,
      "text": "3. Configure Your Modules",
      "id": "3-configure-your-modules",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#3-configure-your-modules"
    },
    {
      "level": 3,
      "text": "4. Deploy",
      "id": "4-deploy",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#4-deploy"
    },
    {
      "level": 2,
      "text": "Security Built In",
      "id": "security-built-in",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#security-built-in"
    },
    {
      "level": 2,
      "text": "Observability and Monitoring",
      "id": "observability-and-monitoring",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#observability-and-monitoring"
    },
    {
      "level": 2,
      "text": "Best Practices",
      "id": "best-practices",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#best-practices"
    },
    {
      "level": 2,
      "text": "Contributing and Support",
      "id": "contributing-and-support",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#contributing-and-support"
    },
    {
      "level": 2,
      "text": "Ready to Explore",
      "id": "ready-to-explore",
      "url": "https://cloudon-one.com/blog/kubernetes-platform-terraform-modules#ready-to-explore"
    }
  ],
  "date_published": "2025-01-08T00:00:00.000Z",
  "tags": [
    "Kubernetes",
    "Terraform",
    "DevOps",
    "Platform Engineering"
  ],
  "content_markdown": "---\ntitle: Building a Kubernetes platform with Terraform modules\ndescription: A guide to reusable modules for Kubernetes autoscaling, networking, secrets, deployment tools, and monitoring.\nurl: https://cloudon-one.com/blog/kubernetes-platform-terraform-modules\nauthor: CloudOn\nlanguage: en\ndate_published: '2025-01-08T00:00:00.000Z'\ntags:\n  - Kubernetes\n  - Terraform\n  - DevOps\n  - Platform Engineering\nrights_url: https://cloudon-one.com/terms\n---\n\n# Building a Kubernetes platform with Terraform modules\n\nA Kubernetes platform needs more than a cluster. Autoscaling, networking, secrets, monitoring, and deployments each bring their own settings and dependencies. This collection groups those configurations into Terraform modules that you can use independently.\n\n## Why Use These Modules\n\n**Reusable configuration** — Each module handles the installation and configuration of one platform component. Start with the modules you need and review their defaults for your environment.\n\n**Consistency** — Modules enforce naming conventions, label standards, and configuration patterns across every environment, reducing drift between development, staging, and production clusters.\n\n**Modularity** — Compose only the components you need. Each module is independently usable; there is no requirement to adopt the entire collection.\n\n**Security First** — RBAC, TLS, network policies, and secret management are built into the modules by default rather than treated as afterthoughts.\n\n## Core Modules at a Glance\n\n### Core Infrastructure\n\n| Module | Purpose |\n|---|---|\n| Karpenter | Node autoprovisioning based on pending pod scheduling constraints |\n| External DNS | Automatic DNS record management from Kubernetes Service and Ingress resources |\n| Cert Manager | Automated TLS certificate issuance and renewal via Let's Encrypt or private CAs |\n| External Secrets | Synchronize secrets from AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault into Kubernetes Secrets |\n\n### Service Mesh and Networking\n\n| Module | Purpose |\n|---|---|\n| Istio | mTLS between services, traffic management, and fine-grained authorization policies |\n| Kong | API gateway with rate limiting, authentication plugins, and developer portal |\n| Jaeger | Distributed tracing with OpenTelemetry-compatible instrumentation |\n\n### Observability\n\n| Module | Purpose |\n|---|---|\n| Loki | Log aggregation and querying with Grafana integration |\n| Kubecost | Real-time Kubernetes cost allocation and showback |\n| ArgoCD | GitOps continuous delivery with drift detection and automated sync |\n\n### Platform Tools\n\n| Module | Purpose |\n|---|---|\n| Airflow | Workflow orchestration for data pipelines and scheduled jobs |\n| Atlantis | Terraform pull request automation with plan/apply workflows |\n| Vault | Secrets management, dynamic credentials, and PKI |\n\n## Architecture Overview\n\nThe modules are organized into five logical layers that map to the platform stack from bottom to top:\n\n| Layer | Components |\n|---|---|\n| Infrastructure Management | Karpenter, External DNS, Cert Manager, External Secrets |\n| Service Mesh and Security | Istio, Kong, Jaeger |\n| Observability | Loki, Kubecost, Prometheus, Grafana |\n| Automation and CI/CD | ArgoCD, Atlantis, Airflow |\n| External Access | Ingress controllers, API gateways, load balancers |\n\nEach layer depends only on layers below it, making it straightforward to add or replace components at any level without affecting the rest of the stack.\n\n## Getting Started\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/cloudon-one/k8s-platform-modules.git\ncd k8s-platform-modules\n```\n\n### 2. Pick Your Modules\n\nReference only the modules you need from your root Terraform configuration:\n\n```hcl\nmodule \"cert_manager\" {\n  source  = \"./modules/cert-manager\"\n  version = \"~> 1.0\"\n\n  cluster_name      = var.cluster_name\n  lets_encrypt_email = var.lets_encrypt_email\n}\n\nmodule \"external_secrets\" {\n  source = \"./modules/external-secrets\"\n\n  cluster_name    = var.cluster_name\n  aws_region      = var.aws_region\n  service_account = \"external-secrets-sa\"\n}\n```\n\n### 3. Configure Your Modules\n\nEach module exposes a focused set of input variables. For example, to configure the Loki module:\n\n```hcl\nmodule \"loki\" {\n  source = \"./modules/loki\"\n\n  cluster_name       = var.cluster_name\n  storage_bucket_name = var.loki_bucket\n  retention_days     = 30\n  replicas           = 2\n}\n```\n\n### 4. Deploy\n\n```bash\nterraform init\nterraform plan -out=tfplan\nterraform apply tfplan\n```\n\n## Security Built In\n\n**RBAC** — Every module creates the minimum set of ClusterRoles and RoleBindings required for the component to function. Service accounts are namespaced and never granted cluster-admin.\n\n**TLS** — Modules that expose endpoints configure TLS by default using Cert Manager. Istio enforces mTLS in STRICT mode across all mesh-enrolled namespaces.\n\n**Network Policies** — Modules ship with default NetworkPolicy resources that restrict ingress and egress to only the traffic paths each component legitimately requires.\n\n**Secret Management** — Sensitive values (credentials, tokens, certificates) are never stored in Terraform state in plaintext. Modules integrate with External Secrets or Vault to pull secrets at runtime.\n\n## Observability and Monitoring\n\nThe observability modules provide a cohesive monitoring stack out of the box:\n\n- **Prometheus** scrapes metrics from all platform components using pre-built ServiceMonitor and PodMonitor resources.\n- **Grafana** ships with pre-configured dashboards for each installed module, giving immediate visibility into cluster health, cost allocation, and application performance.\n- **Alarms** — Key SLO-aligned alerting rules are included for each component, covering availability, latency, and error rate thresholds.\n\n## Best Practices\n\n- Pin each module to a specific version tag rather than using a branch reference to ensure reproducible deployments.\n- Use separate Terraform workspaces or state backends for each environment (development, staging, production).\n- Run `terraform plan` in CI on every pull request and require approval before `terraform apply` reaches production — the Atlantis module automates this workflow.\n- Review Kubecost dashboards weekly to identify namespace-level cost anomalies early.\n- Rotate secrets and certificates on a defined schedule; use Vault's dynamic secrets capabilities wherever possible to reduce the blast radius of a compromised credential.\n\n## Contributing and Support\n\nContributions are welcome. To propose a new module or an improvement to an existing one:\n\n1. Open an issue describing the use case and the component you want to add or change.\n2. Fork the repository and implement the change following the existing module structure.\n3. Submit a pull request with a description of what the module does, the variables it exposes, and a working example in the `examples/` directory.\n\nFor questions and discussion, open a GitHub issue on the repository.\n\n## Ready to Explore\n\nStart with the module that addresses your next platform task. Read its inputs and example configuration, then test it in a development cluster before using it elsewhere.\n",
  "content_sha256": "a2a32f19bc3ca761a0c238489f2a3e0e706d6aa1f3c431ce7be0a38ca8f659dc"
}
