- A main “K8s” directory containing:
- An “api” folder that holds Kubernetes configurations for your API.
- A “cache” folder that contains configurations for your cache service (for example, a Redis instance).
- A “db” folder that stores configurations for your database service (for example, a MongoDB instance).
Below is an example Kubernetes Service configuration for Redis:
Deploying Without Kustomize
To deploy resources without Kustomize, open your terminal, navigate into each directory, and run the appropriate commands. For example:Deploying resources sequentially can help troubleshoot issues more effectively, as you can pinpoint where a problem occurs.
Introducing Kustomize
Kustomize simplifies resource management by allowing you to create a single, consolidated kustomization file at the root of your “K8s” directory. Begin by creating akustomization.yaml file in the K8s directory with the content below:
kustomize build only displays the final output without applying the configurations. To apply the built manifests, pipe the output into kubectl apply:
Using Kustomize can significantly reduce the complexity of managing resources in your cluster, especially as your application scales.
Refining the Directory Structure with Nested Kustomization Files
For enhanced scalability, you can place akustomization.yaml file within each subdirectory. This modular approach lets each folder manage its own resources independently. The root kustomization.yaml then simply references these subdirectories.
For the API Folder
Create akustomization.yaml file inside the “api” folder with the following content:
For the Cache Folder
Inside the “cache” folder, create akustomization.yaml file:
For the DB Folder
Similarly, in the “db” folder, create akustomization.yaml file:
kustomization.yaml to reference the subdirectories, each containing its own kustomization.yaml:
This modular approach, which utilizes nested
kustomization.yaml files, makes managing and scaling your Kubernetes configurations easier as your application grows. For more in-depth information on Kubernetes resources and configuration best practices, explore the following resources: