The Simplest Way to Make Kustomize and Nats Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using kustomize and nats together lets teams manage message broker manifests without copying files. Kustomize patches cluster settings per stage while NATS moves messages between services fast. This workflow keeps base manifests clean across dev, staging, and prod clusters. Teams define one base setup for the message server and apply small overlays. Each overlay changes replica counts, storage size, and user roles for that stage. How kustomize and nats handle keys and message flow Kustomize

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Using kustomize and nats together lets teams manage message broker manifests without copying files. Kustomize patches cluster settings per stage while NATS moves messages between services fast.

This workflow keeps base manifests clean across dev, staging, and prod clusters. Teams define one base setup for the message server and apply small overlays. Each overlay changes replica counts, storage size, and user roles for that stage.

How kustomize and nats handle keys and message flow

Kustomize builds the Kubernetes manifests that deploy your NATS cluster and its config maps. It takes a shared base folder and merges stage overlays before deploy time. The output contains stateful sets, services, and secret objects for your message servers.

Once deployed, the message server reads its config file from those mounted volumes. Apps log in to the cluster using accounts, token keys, or TLS certificates. Each account splits message traffic into isolated spaces so teams do not collide.

Within an account, permissions control which subjects a service can read or write. When you update a subject rule in an overlay, Kustomize updates the config map. You then reload the server so the new rule takes effect right away.

This pattern keeps all routing rules and account limits inside version control. Platform teams review small diff files in pull requests before any change goes live. No one edits live cluster files by hand during a busy release.

Common failure modes and how to scope roles

A common mistake is putting raw keys inside base or overlay files in Git. Anyone with repo read rights can then steal those keys and read messages. Instead, use an external secret tool to inject keys inside the cluster.

Another frequent error is sharing one broad NATS account across every microservice. If one app breaks or leaks its key, all message subjects sit exposed. Give each service its own role with strict read and write subject limits.

End-to-End Encryption + Kustomize Security Overlays: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Teams also run into trouble when config map names stay static during updates. If the name does not change, pods might not pick up the new settings. Let Kustomize append a content hash to every config map and secret name. When you change a setting, the hash changes and triggers a rolling update.

Network paths between client pods and message brokers also need tight rules. Without Kubernetes network policies, any pod in the cluster can reach the broker port. Add network policies in your overlays so only approved namespaces can talk to NATS.

Testing overlays and auditing message traffic

Broken overlays can take down message routing if you push them without checks. Always build the final manifests in your CI pipeline and check the output. Run a schema check tool to catch bad syntax before anything hits the cluster.

You should also watch how client apps use subjects in staging and prod. Unlogged traffic makes it hard to spot noisy services or bad subject names. Turn on server logs for account connections and permission errors in your prod overlay.

Keep staging and prod overlays as close in structure as you can. Only vary resource limits, replica counts, and account keys between those two stages. When messages carry sensitive data like emails or card numbers, mask those fields early. Masking rewrites matched fields in results before downstream apps log or store them.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How do we rotate NATS keys managed by Kustomize?

Store the actual keys in an external secret store outside your Git repo. Update the secret version in your overlay so Kustomize rolls the pods safely.

Should JetStream storage settings live in the base or overlay?

Put the core JetStream toggle in the base manifest so all stages match. Put disk sizes and replica counts in overlays since dev needs less space.

How do we stop one team from reading another team's subjects?

Create separate NATS accounts for each team inside your server config map. Use explicit export and import rules when two teams need to share data.

The query runs. The emails stay hidden.