What are Kustomize Overlays?
Kustomize overlays are a way to customize Kubernetes manifests without modifying the original files. Think of it as inheritance in object-oriented programming - you have a base class (base configuration) and derived classes (overlays) that extend or override specific properties.Base Layer
Generic, reusable configurations that work across any environment
Overlay Layer
Environment-specific customizations that extend or patch the base
No Duplication
Write configuration once, customize as needed per environment
Clear Separation
Infrastructure code separated from environment-specific values
The Two-Layer Pattern
Kimbernetes implements a two-layer overlay structure:Base Configurations
Base configurations contain environment-agnostic definitions. They should be generic enough to work in any environment with appropriate overlays.Example: cert-manager Base
- kustomization.yaml
- namespace.yaml
- helm-repository.yaml
- helm-release.yaml
The base kustomization file lists all resources:Simple and straightforward - just references the component’s manifests.
Environment Overlays
Environment overlays reference the base and add customizations. They inherit all base resources and can:- Set namespaces
- Add additional resources
- Patch existing resources
- Override values
Example: cert-manager Kimawesome Overlay
The kimawesome overlay for cert-manager is minimal:- References the base:
../../../base/cert-managerincludes all base resources - Sets the namespace: All resources will be deployed to
cert-managernamespace - Can be extended: Additional resources or patches can be added here
Overlay with Customizations
For more complex cases, overlays can add resources and patches:- ClusterIssuer resource specific to kimawesome (e.g., Let’s Encrypt production)
- Certificate resource for kimawesome domains
- Helm values patch to enable Prometheus monitoring
Patching Strategies
Kustomize supports several patching strategies for modifying resources:- Strategic Merge
- JSON Patch (RFC 6902)
- Inline Patch
Merge new values with existing configuration:This merges the new values with existing ones in the HelmRelease.
Complete Example: MetalLB
Let’s examine a complete overlay example from Kimbernetes:Base Configuration
overlays/base/metallb/kustomization.yaml:overlays/base/metallb/helm-release.yaml:
Environment Overlay
overlays/kimawesome/loadbalancer/kustomization.yaml:The kimawesome overlay adds environment-specific IP pools and L2 advertisement configuration.
Environment-Specific Resources
overlays/kimawesome/loadbalancer/ip-address-pool.yaml:overlays/kimawesome/loadbalancer/l2-advertisement.yaml:These resources are specific to the kimawesome environment and would differ in other environments.
Overlay Organization Patterns
Kimbernetes organizes overlays by function rather than by technology:loadbalancer/
loadbalancer/
Purpose: Load balancer configuration (MetalLB)Contains IP address pools and L2 advertisement settings specific to the kimawesome network.Why separate?: Load balancer is foundational infrastructure that other components depend on.
infrastructure/
infrastructure/
Purpose: Core infrastructure servicesSubdirectories include:
cert-manager/- TLS certificate managementsealed-secrets/- Secret encryptionobservability/- Monitoring and logging stackgatewayapi/- Gateway API resourcesvpn/- VPN connectivity
metallb via dependsOn in Flux Kustomization.applications/
applications/
Purpose: Application workloadsSubdirectories include:
dns-server/- Internal DNStooling/- Utility applications (n8n, yopass)version-management/- Version control systemssteering-k8s/- Cluster management tools
site/
site/
Purpose: Website and documentationContains knowledge hub and article deployments.Why separate?: Website updates frequently and independently from infrastructure.
Creating a New Overlay
Advanced Techniques
- ConfigMap Generators
- Secret Generators
- Images
- Namespace Transformation
- Common Labels
- Replica Transformation
Generate ConfigMaps from files or literals:Kustomize automatically handles ConfigMap updates by appending a hash to the name, triggering pod restarts.
Best Practices
Keep Base Generic
Base configurations should work across environments without modification. Avoid hardcoding environment-specific values.
Use Descriptive Names
Name directories and files clearly. Use
helm-release.yaml, not release.yaml.Minimize Patches
Prefer adding new resources over patching existing ones. Patches can become complex and hard to maintain.
Document Overrides
Comment why environment-specific overrides exist, especially for non-obvious changes.
Test Locally
Use
kustomize build to preview the final manifests before committing:Organize by Function
Group related components together (infrastructure, applications, etc.) rather than by technology.
Debugging Overlays
- Build Locally
- Check Flux Build
- Validate Syntax
- Diff Changes
Preview what Flux will apply:
Troubleshooting Common Issues
Error: No resources found
Error: No resources found
Cause: The
kustomization.yaml doesn’t reference any manifests.Solution: Ensure the resources list includes all necessary files or directories:Error: Resource already exists
Error: Resource already exists
Cause: Multiple overlays are trying to create the same resource.Solution:
- Check for duplicate resource definitions
- Use namespaces to isolate resources
- Ensure only one Kustomization manages each resource
Patch not applying
Patch not applying
Cause: The target selector doesn’t match any resources.Solution: Verify the target kind, name, and namespace match exactly:
Values not merging correctly
Values not merging correctly
Cause: Kustomize strategic merge vs JSON patch confusion.Solution: For complex value overrides, use JSON patch with explicit paths:
Next Steps
Adding Applications
Step-by-step guide to adding new applications using overlays
Managing Secrets
Learn how to handle secrets in overlays with Sealed Secrets
Flux Components
Understand how the kustomize-controller processes overlays
Repository Structure
Review the complete repository organization