Cloud Native 5 min read

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.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Using Kustomize for Kubernetes Configuration Management and Multi‑Environment Deployments

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.yaml

Generating 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: Opaque

Updating Container Images

images:
- name: nginx
  newName: my-registry/nginx
  newTag: v1

Updating Replicas

replicas:
- name: nginx
  count: 5

Patching Object APIs

patches:
- target:
    kind: Deployment
  patch: |
    - op: replace
      path: /apiVersion
      value: apps/v2

All 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: v1

Dev overlay example:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../../base

namespace: apps-dev
nameSuffix: -dev
replicas:
- name: nginx
  count: 2
commonLabels:
  env: dev

Staging 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: stg

Build commands:

# dev
kustomize build env/dev

# stg
kustomize build env/stg

For more details, refer to the official Kustomize documentation at kustomize.io .

KubernetesConfiguration ManagementDevOpsGitOpsArgo CDKustomizemulti-environment
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.