This guide covers managing Kubernetes configuration directories and using Kustomize for efficient deployments.
In this demo, we review how to efficiently manage your Kubernetes configuration directories. The example uses a structured “k8s” directory containing three subdirectories, each dedicated to a distinct application component:
api/ – Contains Kubernetes configurations for your API.
cache/ – Hosts configurations for caching mechanisms, such as Redis.
db/ – Stores configurations for your MongoDB database.
Within each subdirectory, YAML files define deployments, services, config maps, and other Kubernetes resources. This guide describes the setup, key commands, and benefits of using Kustomize to streamline deployments.
Inside the db/ folder, one YAML file defines a standard Kubernetes Deployment for a MongoDB container. The configuration sets one replica and sources environment variables (username and password) from a config map named “db-credentials.”
To deploy these configurations without Kustomize, open your terminal and use the kubectl apply command to apply manifests from the “k8s” directory. For example:
Copy
Ask AI
kubectl apply -f k8s/
This command deploys all configurations within the “k8s” folder. Alternatively, you can apply each subdirectory individually:
Kustomize simplifies resource management by consolidating multiple YAML files into a single manifest. Begin by creating a kustomization.yaml file at the root of your k8s directory. This file should list all the resource files to be customized.Start with these basic declarations:
For a scalable approach, create individual kustomization.yaml files within each subdirectory (api, cache, db). Then, update the root kustomization.yaml file to reference these folders.
This guide has walked you through managing multiple Kubernetes configuration directories and transitioning from standard kubectl apply methods to using Kustomize for a more scalable solution. For further details, check out the Kubernetes Documentation.