CoursesKustomizeIntermediate

Components & reuse

Optional, composable feature sets.

Intermediate12 min · lesson 8 of 12

A component is a reusable, optional slice of configuration you can mix into multiple overlays — the answer to “these three environments all need the monitoring sidecar, but not the others.” Unlike a base (which an overlay fully inherits), a component is composable: it contributes resources and patches that get applied wherever you list it, so you assemble an environment from a base plus the components it opts into.

ASSEMBLING ENVIRONMENTS FROM COMPONENTS
Base (fully inherited)
Shared manifests
deployment, service
Components (optional, composable)
monitoring
ServiceMonitor + metrics-port patch
network-policy
hardening
dev overlay
base + monitoring
opts into one component
prod overlay
base + all three
monitoring + network-policy + hardening
Each overlay is a base plus the self-contained components it opts into — composition over copy-paste.
components/monitoring/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component # note: Component, not Kustomization
resources:
- servicemonitor.yaml
patches:
- path: add-metrics-port.yaml # patch the base Deployment to expose metrics
---
# an overlay opts in:
# components:
# - ../../components/monitoring

Composition over duplication

Components let you express features independently and combine them per environment: a prod overlay might include the monitoring, network-policy, and hardening components while dev includes only monitoring. Because each component is a self-contained unit of resources-plus-patches, you avoid copy-pasting the same additions into every overlay. It is the Kustomize equivalent of feature toggles, done through composition rather than conditionals.

Component order can matter when patches overlap
Components are applied in the order listed, and if two components patch the same field, the later one wins — so a subtle bug appears when composition order changes the result. Keep components independent where possible, and when they must touch the same resource, be deliberate about ordering and verify the build output, since the final manifest is the sum of all applied components in sequence.