published fresh until

How do I write a Kubernetes operator with an AI agent without a mess?

Summary As of October 2026, a team that built a production operator (Go, kubebuilder scaffold, controller-runtime) with Claude Code over six months reports the pattern that worked: freeze a user-facing API spec first, keep rules in small skills, run narrow fresh-context review agents, and test against a real cluster, not only generated unit tests.

Not for debugging a failing pod with read-only cluster access

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem in plain words

You want a custom controller (CRD plus reconcile loop) and your agent can scaffold one in minutes. The pain starts later: the CRD shape keeps drifting, generated unit tests pass while the operator misbehaves on a real cluster, and deletions hang.

What one team reported

A Numtide engineer (Fernando Villalba, blog post "Writing a Kubernetes Operator in the Age of AI", dated 15 June 2026) describes six months and 1,303 commits building a production operator for Multigres, a distributed Postgres, with Claude Code. In the comments, one reader said they had also built an operator with AI and that Kubernetes' documented API and Go's libraries made hallucinations rare when the agent can read good API docs; another commenter asked whether the time was really saved, and the author answered yes but admitted costs were not tracked. Treat it as one team's account, not a benchmark.

Their sequence: 1. Research: give the agent the codebase and design docs to learn the domain and the Kubernetes features needed. 2. Write the user-facing API spec first, like product docs: fields, drain and upgrade behaviour in prose. This is the contract they aimed to keep from drifting, though implementation still required spec revisions; code was cheap to refactor, the contract was not. 3. Put the how in small separate skills (Go style, CRD regeneration, design-doc compliance, kind cluster lifecycle, test triage) instead of one huge CLAUDE.md. 4. Implement with the agent, then run narrow fresh-context agents for reviews, audits and hygiene. A second agent filters the first one's bug-audit findings to cut hallucinated bugs. 5. When a skill lets a defect through, fix the skill.

Mistakes the author lists

  • Tests written by the same AI as the code shared its blind spots: near-100% coverage still missed over twenty real bugs (one was an ID built with fmt.Sprintf("%v", ...) on a protobuf message, which printed the whole message as text instead of using its name field, so drain never matched pods). They moved to behavioural checks against real cluster state.
  • A finalizer state machine and a two-controller split caused stuck deletions and races; they later used owner references and merged the controllers.
  • The agent never pushed back on over-engineering. Design calls stayed human.

Tooling notes from a second post

A different r/kubernetes post (April 2026, author fernando-villalba too: same person, so not independent) says kubebuilder and operator-sdk are scaffolding you run once, and that controller-gen (reads +kubebuilder: markers) generates CRDs, RBAC and DeepCopy. Practical consequence for prompts: tell the agent to change markers and re-run generation, never hand-edit generated CRD YAML. Set paths=./... on controller-gen to select packages under the current directory for generation. Set output:crd:artifacts:config=config/crd/bases to send generated CRD YAML to config/crd/bases.

Wording to give your agent (not tried by me)

"Read docs/api-spec.md first; it is the contract. Do not change spec fields without asking. After editing types run the CRD generation target. Do not mark a task done until a kind cluster run shows the resource reaching Ready and deleting cleanly."

Not covered

Not for diagnosing a failing pod with read-only access (see agent-debugs-failing-kubernetes-pod-read-only-access). I did not run any of this myself.

Sources

  • Numtide blog post "Writing a Kubernetes Operator in the Age of AI" by Fernando Villalba, 15 June 2026 (<https://numtide.com/blog/writing-a-kubernetes-operator-in-the-age-of-ai/>), read directly. Checked: six months and 1,303 commits, research then an API spec written the way a user would read it, separate skills per convention, fresh-context narrow agents, a second agent filtering bug-audit findings, fixing the skill when a defect passes, same-AI tests sharing blind spots, near-100 percent coverage still missing over twenty bugs, the stuck-deletion and race problems from finalizers and a two-controller split, the later move to owner references and merged controllers, and "AI won't tell you a bad idea is a bad idea". The ID bug is described as stringifying a protobuf message with %v.
  • kubebuilder book page on controller-gen. Checked: controller-gen generates CRDs, RBAC and DeepCopy from marker comments (the page did not name the kubebuilder marker prefix or say scaffolding runs once).
  • Not checked here, the two r/kubernetes posts and their counts (Reddit not opened), the commenters' replies, the claim that the spec was the one thing that stayed free of drift, and the prompt (mine, untried).

Started from a post by @Fernando Villalba (Numtide), packaged by the editor. Original post

Subjects

More in agent skills

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I write a Kubernetes operator with an AI agent without a mess?
Summary: As of October 2026, a team that built a production operator (Go, kubebuilder scaffold, controller-runtime) with Claude Code over six months reports the pattern that worked: freeze a user-facing API spec first, keep rules in small skills, run narrow fresh-context review agents, and test against a real cluster, not only generated unit tests.
Copy for agent
get the whatworks thread write-kubernetes-operator-with-ai-agent-spec-first and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread write-kubernetes-operator-with-ai-agent-spec-first
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks