Folder Structure
A typical Kustomize project is organized into two main sections:- Base Configuration: Contains the shared Kubernetes configurations.
- Overlay Directories: Contains environment-specific folders where you can adjust or extend the base configuration using patches or by adding new resources.
Base Configuration
The base configuration contains all the shared resources used across environments. For example, a basekustomization.yaml could reference your primary Kubernetes resources:
nginx-depl.yaml, might look like this:
Overlays Using Patches
One of the key benefits of Kustomize is its ability to use overlays to modify the base configuration specific to each environment. Overlays allow you to apply patches that adjust parameters such as replica counts without duplicating the entire base configuration.Example: Development Environment
In the development overlay, you may want to increase the replica count from 1 to 2. Thekustomization.yaml file in the dev directory could be structured as follows:
bases field points to the common base configuration, and the patch adjusts the /spec/replicas property specifically for the development environment.
Example: Production Environment
For the production environment, if you want to set the replica count to 3, the overlay’skustomization.yaml would look similar with a slight change:
Adding New Resources in Overlays
Overlays are not limited to patching existing resources; they can also introduce new resources that are unique to an environment. For example, in a production overlay, you might add a Grafana deployment. The directory structure can be updated as follows:kustomization.yaml, you can include the additional Grafana resource:
Flexibility in Directory Structure
Kustomize’s flexible design helps manage complexity by separating common configurations from environment-specific customizations. This approach lets you centralize shared settings in one place and maintain clear, organized overlays for each environment.Using overlays reduces configuration duplication and streamlines the management of different deployment environments. This approach ensures consistency across environments while allowing specific modifications as needed.