Interview Infrastructure as Code (Terraform, Ansible)

How do overlays customise a base without copying it?

Infrastructure as Code (Terraform, Ansible) · Advanced level

Answer

Overlays customize a base by referencing it and applying patches or transformations rather than copying the YAML. This keeps common resources in one place and lets dev, staging, and prod differ only where they must.

Technical explanation

Patches are applied at build time, so source control contains both common YAML and environment deltas.

This prevents divergence where dev and prod copies silently drift apart.

Small overlays are easier to audit than full copied manifests.

Keep source manifests or IaC definitions readable enough that reviewers can understand the final desired state.

Use overlays, modules, or roles for reuse, but keep environment-specific differences explicit and reviewable.

Validate generated output in CI before applying it through kubectl, Argo CD, Terraform, or Ansible.

Hands-on example

1. Create a Kustomize base and overlay for: How do overlays customise a base without copying it?

2. Base files:

base/deployment.yaml

base/service.yaml

base/kustomization.yaml

base/kustomization.yaml:

resources:

- deployment.yaml

- service.yaml

commonLabels:

app.kubernetes.io/name: payments

3. prod overlay:

resources:

- ../../base

namePrefix: prod-

namespace: payments-prod

images:

- name: ghcr.io/company/payments

newTag: 1.8.4

configMapGenerator:

- name: app-config

literals:

- LOG_LEVEL=info

patches:

- path: replica-patch.yaml

4. Render and apply:

kubectl kustomize overlays/prod

kubectl diff -k overlays/prod

kubectl apply -k overlays/prod

5. In GitOps, point Argo CD at overlays/prod and let it render, compare, and sync the desired state.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Infrastructure as Code (Terraform, Ansible) interview questions

← All Infrastructure as Code (Terraform, Ansible) questions