This guide explains how to define and use components in Kustomize for packaging optional features into reusable configuration blocks.
In this guide, you’ll learn how to define and consume components in Kustomize. Components let you package optional features—such as additional resources, patches, ConfigMaps, or Secrets—into self-contained units. You can then import them in selected overlays without duplicating code, ensuring consistency and reducing configuration drift.
Use components when an application offers optional features that only apply to some overlays. If a feature is required in all overlays, include it in your base. For features needed by only a subset, bundle them as components to avoid repetition.
Our shared base/ folder holds common resources. We also have two optional features:
Caching (backed by Redis) — enabled in premium and standalone
External DB (Postgres) — enabled in dev and premium
Where should we place the Redis and Postgres manifests so only the right overlays include them?
Instead of duplicating manifests in overlays—or adding unwanted features to base—we create two components (caching and db) and import them selectively.