Skip to main content
In this lesson we walk through managing Kubernetes manifests across multiple directories and show how Kustomize can simplify deployments and keep manifests modular as your project grows. Project layout
  • A top-level k8s/ directory containing three subfolders:
    • api/ — Kubernetes manifests for the API service
    • cache/ — Kubernetes manifests for Redis
    • db/ — Kubernetes manifests for MongoDB
Each folder contains the typical resources: Deployments, Services, and ConfigMaps. Below are representative snippets and the commands used during the demo. Project structure (quick reference) Example Deployment (Mongo)
  • This is a complete Deployment manifest for the MongoDB container (example shows environment variables sourced from a ConfigMap named db-credentials).
Example Service (Redis ClusterIP)
Manual apply without Kustomize
  • The simplest approach is to apply each directory directly with kubectl apply -f <dir>. This is straightforward for small projects.
You can also pass multiple -f flags in one command:
Example (cleaned) console output from applying directories:
This manual approach works, but it becomes tedious and error-prone as manifests and directories increase. Using Kustomize — single root Kustomization.yaml
  • A common way to consolidate manifests is to add a Kustomization.yaml at the root of k8s/ that lists resources from subdirectories. This produces a single combined set of YAML documents.
Example k8s/Kustomization.yaml (single root approach):
Preview the combined manifests (no apply):
The build prints the full combined YAML for all resources (excerpt):
Apply the generated manifests to the cluster:
Example (cleaned) apply output:
Note: kubectl includes built-in Kustomize support, so you can do the same with:
You can use either the standalone kustomize CLI piped into kubectl apply -f - or the built-in kubectl apply -k <directory>. Both produce the same result.
Verify pods are running:
Example output:
Using Kustomize — per-directory Kustomization.yaml (recommended)
  • For better modularity and maintainability, create a Kustomization.yaml inside each subdirectory (api/, cache/, db/) and then have the root k8s/Kustomization.yaml reference those directories. Kustomize will read the subdirectory Kustomization.yaml files.
Example api/Kustomization.yaml:
Example cache/Kustomization.yaml:
Example db/Kustomization.yaml:
Then update the root k8s/Kustomization.yaml to reference the directories (Kustomize will look for their Kustomization.yaml files):
Build and apply:
  • Build combined manifests:
  • Apply with kubectl (preferred shorthand):
Or:
Example apply output:
Verify:
Expected output:
Comparison: single root vs per-directory Kustomization Summary
  • Both a single root Kustomization.yaml and per-directory Kustomization.yaml files are valid. For growing projects, the per-directory (modular) approach is recommended.
  • Use kustomize build <dir> to preview merged manifests and apply with either kustomize build <dir> | kubectl apply -f - or the shorthand kubectl apply -k <dir>.
Links and references

Watch Video

Practice Lab