Using Kustomize for Kubernetes Configuration Management and Multi‑Environment Deployments
This article demonstrates how to use Kustomize to manage Kubernetes manifests, generate ConfigMaps, Secrets, update images and replicas, create multi‑environment overlays, and render the final YAML for deployment with kubectl or Argo CD, assuming basic Kubernetes knowledge and the Kustomize CLI installed.
This article demonstrates how to use Kustomize to manage Kubernetes manifests, render them with the Kustomize CLI, and deploy the resulting YAML directly to a cluster using kubectl or through a continuous delivery tool such as Argo CD. Prerequisites include basic Kubernetes knowledge and an installed Kustomize CLI (see the official installation guide).
Kustomize Overview
Kustomize provides a template‑free way to customize application configurations, allowing a single base set of YAML files to be adapted for different environments via variables, patches, and generators.
Configuration Management
Resource Management
The resources field lists the paths to the manifest files that Kustomize will process.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yamlGenerating ConfigMaps and Secrets
Kustomize can generate ConfigMaps and Secrets from files or env files.
configMapGenerator:
- name: nginxconfig
files:
- nginx.conf
secretGenerator:
- name: env_file_secret
envs:
- secrets.txt
type: OpaqueUpdating Container Images
images:
- name: nginx
newName: my-registry/nginx
newTag: v1Updating Replicas
replicas:
- name: nginx
count: 5Patching Object APIs
patches:
- target:
kind: Deployment
patch: |
- op: replace
path: /apiVersion
value: apps/v2All the above snippets are taken from the demo repository 01-resources . After cloning the repo, run kustomize build 01-resources to generate the final manifest.
Multi‑Environment Configuration
A base directory holds the common manifests. Overlays such as dev and stg reference the base and apply environment‑specific customizations.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
secretGenerator:
- name: env_file_secret
envs:
- secrets.txt
type: Opaque
configMapGenerator:
- name: nginxconfig
files:
- nginx.conf
images:
- name: nginx
newName: my-registry/nginx
newTag: v1Dev overlay example:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
namespace: apps-dev
nameSuffix: -dev
replicas:
- name: nginx
count: 2
commonLabels:
env: devStaging overlay example:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
namespace: apps-stg
nameSuffix: -stg
images:
- name: nginx
newName: my-registry/nginx
newTag: v1
replicas:
- name: nginx
count: 5
commonLabels:
env: stgBuild commands:
# dev
kustomize build env/dev
# stg
kustomize build env/stgFor more details, refer to the official Kustomize documentation at kustomize.io .
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.