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

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair kustomize and pytest to build and check cluster files before deployment. Kustomize builds the final manifests, and pytest runs Python tests to catch bad settings. This workflow stops broken files from reaching your live cluster. Your team can test port numbers, image tags, and role rules in seconds. You run these checks on every laptop and inside your build pipeline. How kustomize and pytest share data and permissions The data flow between kustomize and pytest starts with your base

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.

You pair kustomize and pytest to build and check cluster files before deployment. Kustomize builds the final manifests, and pytest runs Python tests to catch bad settings.

This workflow stops broken files from reaching your live cluster. Your team can test port numbers, image tags, and role rules in seconds. You run these checks on every laptop and inside your build pipeline.

How kustomize and pytest share data and permissions

The data flow between kustomize and pytest starts with your base manifest files. Kustomize reads your base files and applies your overlays for staging or prod. It outputs a single stream of text that holds your final cluster objects.

Pytest calls this build step and reads the output into Python memory. Your test functions parse that text into standard Python data structures. Then pytest checks each object against the rules your team wrote.

Most unit tests for manifests do not need live cluster permissions at all. The build tool and test runner only read local files from your code repo. When tests must check a live test cluster, the runner needs a scoped role. That role should only read cluster state or write to one test namespace.

Common failure modes and how to scope roles

Teams often make mistakes when they wire these two tools into build pipelines. A common failure is giving the test runner a shared admin service account. If a test script has broad rights, a bug can delete live apps.

Another failure mode is storing long-lived cluster keys inside the test repo. Anyone who reads the repo can take those keys and log in. Unlogged test queries against live clusters also hide who changed what during a run.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix this by splitting offline checks from live cluster checks. Run all manifest structure checks offline with zero cluster keys in the job. Kustomize builds the text locally, and pytest checks the text in memory.

For live tests, give the test runner a narrow role for one namespace. Lock down the network path so only the build server can reach the cluster. Log every request the test runner makes so your team can audit failures.

How to structure your manifest test suite

Good test suites use pytest fixtures to build each overlay once per test run. If you build the manifests for every single test, the suite runs too slow. A shared fixture builds the staging and prod outputs one time and saves them.

Write small test functions that check one rule at a time. One test can check that every container sets a memory limit. Another test can check that no app uses the latest image tag.

You can also check that secret objects do not hold plain text passwords. If a test fails, pytest shows the exact overlay and object that broke the rule. Developers fix the manifest on their branch before they merge the code.

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

Do I need a running cluster to test manifests with pytest?

No, you do not need a live cluster for most manifest checks. Kustomize builds the YAML output locally, and pytest checks the parsed data in memory.

How do I keep pytest fast when testing many overlays?

Use a session fixture in pytest to run the build step once per overlay. Store the parsed objects in memory and run all your rule checks against them.

What should I test first in my rendered manifests?

Start by checking resource limits, image tags, and required labels across all deployments. Next, check that service ports match container ports in every overlay.

The query runs. The emails stay hidden.