Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 150/ 160
08. Cluster Administration & Managed Cloud Kubernetes

Provisioning Kubernetes Clusters with Terraform / OpenTofu

Codify cluster and node infrastructure with Terraform or OpenTofu modules.

IntermediateTerraform · OpenTofu · IaC3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

IaC is an executable construction drawing: plan shows the proposed demolition and state is the locked inventory against which it is compared. The simple Kubernetes rule is: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Think of it like…

IaC is an executable construction drawing: plan shows the proposed demolition and state is the locked inventory against which it is compared.

Where you’ve seen it

During a controlled maintenance window, the platform operator runs terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan. Expected evidence: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph. If the run instead shows this symptom, stop and restore the last known state: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.

Words you’ll hear

Terraform
For this lesson, Terraform is the controlling idea: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
OpenTofu
OpenTofu is the checkpoint; run terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan and inspect the owner chain. A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.
IaC
IaC is the outcome to preserve; the cost is explicit: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.
Verification evidence
The evidence command is terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan. It connects the declaration to this behavior: Codify cluster and node infrastructure with Terraform or OpenTofu modules.

Visual diagram

Loading interactive diagram

Theory & deep dive

How Terraform reaches the intended state

Codify cluster and node infrastructure with Terraform or OpenTofu modules. Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

The concrete checkpoint is terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan; compare the Terraform owner, OpenTofu state, and IaC outcome instead of treating YAML acceptance as proof.

Verify OpenTofu, not only object creation

Run terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan after the change and correlate the result with Events and the owning object. Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Key takeaway: Terraform is implemented only when this invariant remains observable: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

OpenTofu: failure boundary and production cost

A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another. The prerequisite contract is concrete: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements. A safe design limits blast radius, records the last good configuration, and uses terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan as a deterministic rollback checkpoint.

Recover from OpenTofu drift

Capture the current state with terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.

Key takeaway: Accept the trade-off consciously: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

How it works, step by step

Step 1 of 4
Platform planner

1. Plan the lifecycle boundary

Inventory versions, capacity, state, backups, and ownership in a reversible plan: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Terraform contract → owned state
Key numbers at this step
Goal
Codify cluster and node infrastructure with Terraform or OpenTofu modules.
Owner
Terraform

When to use it & trade-offs

What it is

Codify cluster and node infrastructure with Terraform or OpenTofu modules. Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Why it matters: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another. The invariant at risk is specific: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph. The quickest fact check before changing the design is terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan.

When to reach for it

  • Use Terraform to enforce this invariant: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
  • Use OpenTofu evidence from terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan in reviews and incident timelines. Codify cluster and node infrastructure with Terraform or OpenTofu modules.
  • Choose the managed cloud or platform service route only when this cost is justified by governance or scale: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

When to avoid or be careful

  • Avoid assuming Terraform is complete after YAML submission; the required behavior is concrete: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
  • Avoid treating the next symptom as random; check the owner and state with terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan first: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.
  • Avoid adopting a heavier platform wrapper before measuring its cost: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

Native, manual, and managed paths for Terraform

Repeatable infrastructure control
Best for: Codify cluster and node infrastructure with Terraform or OpenTofu modules. A concrete incident check is terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan.

Strengths: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Watch out: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements. Recovery must also recognize this signal: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.

Manual cluster mutation
Best for: Quickly testing the OpenTofu assumption with terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan; the expected invariant is: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Strengths: terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan gives immediate feedback without first building a platform layer.

Watch out: A manual change can hide drift, and unlike Terraform, it does not make this symptom self-documenting: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.

Managed cloud or platform service
Best for: Teams that need IaC integrated with guardrails; the evidence path is terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan.

Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.

Watch out: The added platform ownership buys value at this cost: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

Interview signals & numbers to know

When this topic comes up

  • Interview anchor: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
  • Trace Terraform to IaC through OpenTofu; the invariant is: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
  • Recognize the symptom: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.
  • Justify the cost: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.
  • Verify with terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan instead of only inspecting YAML.

Benchmarks & rules of thumb

2 -
compatible engines discussed: Terraform and OpenTofu
1 -
reviewed plan artifact should precede production apply
0 -
state files should be committed as ordinary plaintext code

Common mistakes & follow-ups

Common interview mistakes

  • Debugging only the child object misses the Terraform owner contract: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph.
  • Ignoring this telltale condition leads to unrelated changes: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another.
  • Repeating terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan without an owner for remediation wastes retry cost. Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

Likely interviewer follow-ups

  • How would API output and runtime evidence prove this behavior: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph?
  • Which owner object, logs, and Events would you inspect for this symptom-A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another-?
  • At what threshold would this cost become unacceptable: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements?
Interview tip: Interview sequence: state the invariant, run terraform init; terraform plan -out=cluster.tfplan; terraform apply cluster.tfplan, name the failure, then justify the cost. Invariant: Terraform or OpenTofu declares cloud, network, managed cluster, node, and policy resources, with plan and state providing a reviewable lifecycle graph. Failure: A plan can replace the control plane for a cluster name or immutable field, credentials can leak through state, and a bootstrap order bug can make two providers depend on one another. Cost: Declarative IaC improves reproducibility, but remote state locking, module versioning, secret backends, imports, and blast-radius layering are platform requirements.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Provisioning Kubernetes Clusters with Terraform / OpenTofu with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Azure AKS Deep Dive (Azure CNI, Entra ID Workload Identity, KEDA Add-on)
Next topic
Cluster API (CAPI): Declarative Kubernetes Cluster Lifecycle Management