- api/ – Contains Kubernetes configurations for your API.
- cache/ – Hosts configurations for caching mechanisms, such as Redis.
- db/ – Stores configurations for your MongoDB database.
MongoDB Deployment Example
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.”Service and ConfigMap Example
In the cache/ folder, you will find YAML files for Redis. Below is an example of a ClusterIP service definition for a Redis deployment:For additional information on configuring Kubernetes services and ConfigMaps, refer to the official Kubernetes Documentation.
Deploying the Configurations Without Kustomize
To deploy these configurations without Kustomize, open your terminal and use thekubectl apply command to apply manifests from the “k8s” directory. For example:
Introducing Kustomize
Kustomize simplifies resource management by consolidating multiple YAML files into a single manifest. Begin by creating akustomization.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:
kubectl apply:
kubectl:
Explore more Kubernetes best practices in our Kubernetes Basics guide.
Organizing Kustomize Configurations per Directory
For a scalable approach, create individualkustomization.yaml files within each subdirectory (api, cache, db). Then, update the root kustomization.yaml file to reference these folders.
API Directory
Inside the api/ folder, create akustomization.yaml to include the API deployment and service definitions:
Cache Directory
Within the cache/ folder, create akustomization.yaml for Redis configurations:
Database Directory
In the db/ folder, create akustomization.yaml for MongoDB resources:
kustomization.yaml to reference each subdirectory:
kustomization.yaml files, and deploy all the resources accordingly.
Final Deployment and Verification
After removing any previously deployed resources, apply the new configuration structure:Remember to clean up any stale resources in your cluster before applying new configurations to avoid conflicts.
Kubernetes Resource Overview
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.