惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Vercel News
Vercel News
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
量子位
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
IT之家
IT之家
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Zero to Kubernetes Part 2: Cluster Bootstrap — Namespaces...
jesus manriq · 2026-05-20 · via DEV Community

jesus manrique

K8s Terraform ArgoCD — Header

Series: Zero to Kubernetes — Part 1 · Part 2 · Part 3 · Part 4 · Part 5


In Part 1 we built a Kubernetes cluster with Terraform and kubeadm. Three nodes ready but empty. Today we turn it into a usable platform: external traffic with automatic TLS, storage for databases, namespaces that separate environments, and permissions that prevent a staging deploy from destroying production.

All with Terraform. Zero manual kubectl apply.


Why Terraform for Bootstrap and Not ArgoCD?

This is a question we get a lot. The answer lies in the dependency order:

┌─────────────────────────────────────────┐
│  Terraform (infrastructure + bootstrap) │
│  VMs, networks, kubeadm, namespaces,    │
│  ingress, cert-manager, storage, RBAC   │
│  ↓                                      │
│  Terraform installs ArgoCD              │
│  ↓                                      │
│  ArgoCD manages applications            │
│  (backend, frontends, DB)               │
└─────────────────────────────────────────┘

Enter fullscreen mode Exit fullscreen mode

Terraform manages what ArgoCD needs to exist. Once ArgoCD is running, we hand off application control. If you try to use ArgoCD to bootstrap the ingress controller that ArgoCD needs to expose its own UI, you have a circular problem. Terraform breaks that cycle.


What We're Building Today

┌──────────────────────────────────────────────┐
│                 INTERNET                      │
│                    │                          │
│         ┌──────────▼──────────┐               │
│         │  nginx ingress      │               │
│         │  (NodePort 30080)   │               │
│         │  + cert-manager     │               │
│         │  + Let's Encrypt    │               │
│         └──────────┬──────────┘               │
│                    │                          │
│    ┌───────────────┼───────────────┐          │
│    ▼               ▼               ▼          │
│ ┌────────┐  ┌──────────┐  ┌──────────────┐   │
│ │production│ │ staging  │  │infrastructure│   │
│ │namespace │ │namespace │  │ namespace    │   │
│ └────────┘  └──────────┘  └──────────────┘   │
│                                                │
│ Storage: local-path-provisioner (PVC)          │
│ RBAC: ServiceAccounts + Roles                 │
└──────────────────────────────────────────────┘

Enter fullscreen mode Exit fullscreen mode


Step 1: Connect Terraform to the Cluster

We need the Kubernetes provider pointing to the cluster we created in Part 1:

provider "kubernetes" {
  host                   = "https://${hcloud_server.control_plane.ipv4_address}:6443"
  client_certificate     = base64decode(var.k8s_client_cert)
  client_key             = base64decode(var.k8s_client_key)
  cluster_ca_certificate = base64decode(var.k8s_ca_cert)
}

provider "helm" {
  kubernetes {
    host                   = "https://${hcloud_server.control_plane.ipv4_address}:6443"
    client_certificate     = base64decode(var.k8s_client_cert)
    client_key             = base64decode(var.k8s_client_key)
    cluster_ca_certificate = base64decode(var.k8s_ca_cert)
  }
}

Enter fullscreen mode Exit fullscreen mode

Practical note: For this tutorial, we extract certificates from the kubeconfig. In production, use a secrets backend (Vault, AWS Secrets Manager) and inject them as environment variables.


Step 2: Namespaces — the Foundation of Everything

Namespaces are the logical isolation unit in Kubernetes. Without them, all resources live in default and chaos is guaranteed:

resource "kubernetes_namespace" "production" {
  metadata {
    name = "production"
    labels = {
      environment = "production"
      managed-by  = "terraform"
    }
  }
}

resource "kubernetes_namespace" "staging" {
  metadata {
    name = "staging"
    labels = {
      environment = "staging"
      managed-by  = "terraform"
    }
  }
}

resource "kubernetes_namespace" "infrastructure" {
  metadata {
    name = "infrastructure"
    labels = {
      environment = "infrastructure"
      managed-by  = "terraform"
    }
  }
}

resource "kubernetes_namespace" "argocd" {
  metadata {
    name = "argocd"
    labels = {
      environment = "infrastructure"
      managed-by  = "terraform"
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

The convention: production for real workloads, staging for pre-production testing, infrastructure for system components (ingress, cert-manager, storage), argocd for the GitOps tool.


Step 3: Storage — local-path-provisioner

Kubernetes needs a StorageClass that dynamically creates PersistentVolumes when a pod requests a PVC. On Hetzner we use local-path-provisioner (from Rancher), which creates volumes on the node's local disk:

resource "helm_release" "local_path_provisioner" {
  name       = "local-path-provisioner"
  namespace  = kubernetes_namespace.infrastructure.metadata[0].name
  repository = "https://rancher.github.io/local-path-provisioner"
  chart      = "local-path-provisioner"
  version    = "0.0.28"

  set {
    name  = "storageClass.defaultClass"
    value = "true"
  }

  set {
    name  = "nodePathMap[0].node"
    value = "DEFAULT_PATH_FOR_NON_LISTED_NODES"
  }

  set {
    name  = "nodePathMap[0].paths[0]"
    value = "/var/local-path-provisioner"
  }
}

Enter fullscreen mode Exit fullscreen mode

Why not Rook/Ceph? For a modest 3-node cluster, Ceph is overengineering. local-path-provisioner is perfect: data lives in /var/local-path-provisioner on the node where the pod runs. The limitation is that if that node dies, the volume is lost. For serious production, you'd later migrate to Longhorn (replication) or use cloud volumes (Hetzner volumes).


Step 4: nginx Ingress Controller — the Front Door

The ingress controller is the reverse proxy that receives external traffic and routes it to the correct Services inside the cluster. We use nginx, the most battle-tested in the ecosystem:

resource "helm_release" "ingress_nginx" {
  name       = "ingress-nginx"
  namespace  = kubernetes_namespace.infrastructure.metadata[0].name
  repository = "https://kubernetes.github.io/ingress-nginx"
  chart      = "ingress-nginx"
  version    = "4.11.2"

  set {
    name  = "controller.service.type"
    value = "NodePort"
  }

  set {
    name  = "controller.service.nodePorts.http"
    value = "30080"
  }

  set {
    name  = "controller.service.nodePorts.https"
    value = "30443"
  }

  set {
    name  = "controller.config.proxy-body-size"
    value = "50m"
  }

  set {
    name  = "controller.config.proxy-read-timeout"
    value = "60"
  }

  set {
    name  = "controller.config.proxy-send-timeout"
    value = "60"
  }
}

Enter fullscreen mode Exit fullscreen mode

Important details:

  • We use NodePort because Hetzner doesn't have a native LoadBalancer. The ingress listens on port 30080 (HTTP) and 30443 (HTTPS) on every node
  • proxy-body-size: 50m allows file uploads
  • Proxy timeouts at 60s prevent long requests (migrations, backups) from being cut off

Step 5: cert-manager — Automatic TLS with Let's Encrypt

Nobody should be managing TLS certificates manually in 2026. cert-manager creates them, renews 30 days before expiry, and injects them as Secrets:

resource "helm_release" "cert_manager" {
  name       = "cert-manager"
  namespace  = kubernetes_namespace.infrastructure.metadata[0].name
  repository = "https://charts.jetstack.io"
  chart      = "cert-manager"
  version    = "1.16.1"

  set {
    name  = "installCRDs"
    value = "true"
  }

  set {
    name  = "prometheus.enabled"
    value = "false"
  }
}

Enter fullscreen mode Exit fullscreen mode

After installing cert-manager, create the ClusterIssuers:

# Staging — for testing, no strong rate limits
resource "kubernetes_manifest" "cluster_issuer_staging" {
  manifest = {
    apiVersion = "cert-manager.io/v1"
    kind       = "ClusterIssuer"
    metadata = {
      name = "letsencrypt-staging"
    }
    spec = {
      acme = {
        server  = "https://acme-staging-v02.api.letsencrypt.org/directory"
        email   = var.letsencrypt_email
        privateKeySecretRef = {
          name = "letsencrypt-staging-account-key"
        }
        solvers = [{
          http01 = {
            ingress = { class = "nginx" }
          }
        }]
      }
    }
  }
}

# Production — real certificates
resource "kubernetes_manifest" "cluster_issuer_production" {
  manifest = {
    apiVersion = "cert-manager.io/v1"
    kind       = "ClusterIssuer"
    metadata = {
      name = "letsencrypt-production"
    }
    spec = {
      acme = {
        server  = "https://acme-v02.api.letsencrypt.org/directory"
        email   = var.letsencrypt_email
        privateKeySecretRef = {
          name = "letsencrypt-production-account-key"
        }
        solvers = [{
          http01 = {
            ingress = { class = "nginx" }
          }
        }]
      }
    }
  }

  depends_on = [helm_release.cert_manager]
}

Enter fullscreen mode Exit fullscreen mode


Step 6: Minimum Viable RBAC

For this tutorial we need a ServiceAccount that applications will use:

resource "kubernetes_service_account" "apps" {
  metadata {
    name      = "apps-sa"
    namespace = kubernetes_namespace.production.metadata[0].name
  }
}

resource "kubernetes_role" "apps" {
  metadata {
    name      = "apps-role"
    namespace = kubernetes_namespace.production.metadata[0].name
  }

  rule {
    api_groups = [""]
    resources  = ["pods", "services", "configmaps", "secrets"]
    verbs      = ["get", "list", "watch"]
  }

  rule {
    api_groups = ["apps"]
    resources  = ["deployments"]
    verbs      = ["get", "list", "watch"]
  }
}

resource "kubernetes_role_binding" "apps" {
  metadata {
    name      = "apps-rolebinding"
    namespace = kubernetes_namespace.production.metadata[0].name
  }

  role_ref {
    api_group = "rbac.authorization.k8s.io"
    kind      = "Role"
    name      = kubernetes_role.apps.metadata[0].name
  }

  subject {
    kind      = "ServiceAccount"
    name      = kubernetes_service_account.apps.metadata[0].name
    namespace = kubernetes_namespace.production.metadata[0].name
  }
}

Enter fullscreen mode Exit fullscreen mode

This is intentionally restrictive: apps can read resources but not modify or create them. In Part 4 we'll configure a specific ServiceAccount for the backend with Secret read permissions.


What You Learned in This Part

  • Namespaces as an isolation layer between environments
  • Why Terraform manages bootstrap and ArgoCD manages apps
  • nginx ingress controller exposed via NodePort
  • cert-manager + Let's Encrypt for automatic TLS with renewal
  • local-path-provisioner as a dynamic StorageClass
  • Minimum viable RBAC with ServiceAccounts, Roles and RoleBindings
  • The ClusterIssuerIngress annotationSecret TLS → ready certificate flow

In Part 3, we'll deploy ArgoCD, configure GitOps with the app-of-apps pattern, and have our first automated deployment from GitHub.


At Guayoyo Tech, we don't just write tutorials — we design and deploy architectures like this for real companies. Kubernetes, Terraform, ArgoCD, CI/CD pipelines, and the entire cloud-native ecosystem: we build it with you, no hype, no vendor lock-in. Want your infrastructure to look like what you just read? Talk to us free for 15 minutes. Your cluster, your cloud, your rules — we bring the engineering.