Cursor Rules for Kubernetes: Manifests, Contexts, and Reviews

Practical Cursor rules for Kubernetes manifest conventions, cluster context, secret handling, and change reviews, with fenbs recording the operational decisions behind them.

Updated 4 min read

Cursor rules for Kubernetes tell a coding assistant how your team writes manifests, which cluster it is targeting, how to reference secrets, and which changes need a review before they are applied. Without them, an assistant treats every cluster as a fresh start and has no way to know whether a change should go through an approval step. Tools like fenbs record the operational decisions behind these rules, so the next assistant reads the same boundaries the current one worked inside.

This page gives you a working template for each concern, explains the traps to avoid, and shows how to keep the rules current as your cluster setup changes.

What Kubernetes Cursor rules need to cover

A Kubernetes project has several areas where an assistant without context will make plausible but wrong choices. Manifest style is one: resource names, label schemes, and annotation patterns vary by team. Cluster context is another: an assistant that does not know which namespace or cluster is current may generate commands for the wrong target. Secret handling is a third: references to credentials must follow your chosen pattern rather than inlining values.

How you organize the rule files matters almost as much as what they contain. Start with a single file covering all five areas. Once the rules have been refined through a few sessions, split them by concern: manifest rules scoped to **/*.yaml files, cluster context rules applied always, and secret reference rules scoped to files that reference environment variables. This keeps each file focused and easy to update independently when the cluster configuration changes. For patterns that apply across multiple Kubernetes repositories, see the Cursor rules library guide.

  • Manifest conventions: resource naming, required labels, annotation patterns, and ordering of fields.
  • Cluster context: which namespace is active, how to switch clusters, and what a dry-run looks like before applying.
  • Secret references: how to reference a secret (a Kubernetes Secret name, an external secrets reference, or an environment variable source), never the value.
  • Reviewed changes: which resource types require a human approval step before kubectl apply.
  • Lint and validate: whether the project uses kube-linter, kubeconform, or another tool, and when to run it.

Manifest convention rules

Consistency matters across a cluster because a pipeline or a monitoring tool usually reads labels to find resources. If an assistant creates a Deployment without the right labels, it becomes invisible to that tooling. The rules below set the minimum your assistant needs to follow your team's conventions.

Example manifest convention rules for .cursor/rules/kubernetes-manifests.mdc
# Kubernetes manifest conventions

## Naming
- Use kebab-case for all resource names: my-app-backend, not MyAppBackend or my_app_backend.
- Prefix names with the service identifier: payments-api, payments-worker, not just api or worker.

## Required labels
Every resource must include:
  app.kubernetes.io/name: <service-name>
  app.kubernetes.io/component: <api | worker | job | cron>
  app.kubernetes.io/part-of: <product>
  app.kubernetes.io/managed-by: <helm | kustomize | kubectl>

## Field order
Prefer this order in specs: metadata, spec, then nested containers.
List containers before initContainers. List env before envFrom.

## Resource limits
Every container spec must set resources.requests and resources.limits.
Do not omit these even for one-off jobs.

Cluster context rules

An assistant that does not know the active context can generate kubectl commands that run against the wrong cluster. Add a rule that names the expected context and requires a dry-run before any apply. Pair it with a rule about namespace: many teams create resources in the default namespace by accident and only discover it when a probe fails.

Example cluster context rules
# Cluster context

## Active context
The development cluster context is k8s-dev. The staging context is k8s-staging.
Production context is k8s-prod; never target it from a local environment.
Always confirm the current context with `kubectl config current-context` before generating apply commands.

## Namespace
Default namespace is not used. Every resource specifies metadata.namespace explicitly.
Development resources go in dev-<service>. Staging resources go in staging-<service>.

## Dry-run
Before generating any apply or delete command, include a dry-run step:
  kubectl apply --dry-run=server -f <file>
Present the dry-run result to the user before offering the live command.

Secret reference rules

The most important rule in a Kubernetes project is how secrets reach containers. An assistant offered a connection string may inline it as a literal value if no rule says otherwise. State clearly which pattern your team uses and require the assistant to use that pattern only. The checker for this kind of rule is simple: if the word "password", "token", or "key" appears in a manifest value, it is wrong.

Example secret reference rules
# Secret references

## Never inline credentials
Do not place passwords, tokens, API keys, or certificate content directly in a manifest value.
If a credential is offered in a prompt, note the field name it belongs to and generate the
Kubernetes Secret reference instead.

## Reference pattern
This project uses Kubernetes Secrets referenced by secretKeyRef:
  env:
    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: payments-db-secret
          key: connection-string

## External secrets
For secrets managed by External Secrets Operator, generate an ExternalSecret resource pointing
to the SecretStore named aws-secrets-manager-store. Do not create the Kubernetes Secret directly.

Rules for reviewed changes

Some Kubernetes changes need a human decision before they are applied: scaling a production Deployment, changing a PodDisruptionBudget, or updating a network policy. A rule that flags these resources prevents an assistant from presenting an apply command as ready when it actually needs approval. The rule does not need to know every detail of your review process; it just needs to identify the resource types and instruct the assistant to mark them as needing review.

Any change to a review-required resource that is made without following the approval step should be recorded as a lesson in the project record. A bypassed approval that becomes a habit is more dangerous than the original change, because the next session has no way to know the bypass was temporary rather than intentional. Approved exceptions belong in the rule file alongside the rule they deviate from.

Example reviewed-change rules
# Reviewed changes

## Resources that require approval before apply
The following resource types in the staging and production namespaces need a person to approve
before `kubectl apply` is run:
  - Deployment (if replicas or image tag changes)
  - HorizontalPodAutoscaler
  - PodDisruptionBudget
  - NetworkPolicy
  - ClusterRole and ClusterRoleBinding

When generating changes to these resources, end the response with:
  "REVIEW REQUIRED: apply this only after approval in the deployment log."

Do not include the live kubectl apply command for these resources.
How fenbs helps

Record operational decisions where your AI reads them first

fenbs keeps Decisions and rules for each project. When your team agrees that production changes need approval, or that a service should always use the external secrets operator, record that decision in fenbs. Every connected assistant reads the rules first in its AI context, so the rule is there the next time someone starts a Cursor session on the cluster, even after a month away.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

How to do this with fenbs

  1. Create a free account and add a project for the cluster or service you are working on.
  2. Add the operational decisions your team has settled on: naming conventions, secret pattern, which changes need approval. Record each one as a Decision in fenbs, with the person who decided it and the reason.
  3. Connect Cursor to fenbs over MCP from Integrations. Ask Cursor to read the project context at the start of a session before making any manifest changes.
  4. Keep a task in fenbs for any pending cluster change that needs review. Move it to In Progress when work starts and to Completed when the change is applied and verified. The task record carries the context a colleague needs to understand what changed.
  5. When a rule changes, update the Decision in fenbs and the Cursor rule file together. The two should always agree.

For rules that apply across many Kubernetes projects, see the Cursor rules library guide for how to share rule files and keep them consistent across repositories.

Questions people ask.

Where do Cursor rules for Kubernetes live in the project?

Place them in .cursor/rules/ as .mdc files. Each file can target specific glob patterns, such as **/*.yaml or **/k8s/**, so the rules apply when Cursor opens a manifest file. A project-wide rule file can also sit at .cursorrules in the project root, though the .cursor/rules/ directory is the current recommended location.

Can Cursor rules prevent an assistant from applying to the wrong cluster?

A rule can instruct the assistant to confirm the current kubectl context before generating apply commands and to refuse to generate production commands from a local environment. The rule cannot intercept the terminal, but it shapes what the assistant recommends, which is the point where most mistakes begin.

Should I put the Cursor rules in version control?

Yes. Committing the .cursor/rules/ directory means every developer and CI job that uses Cursor works from the same rules. It also lets you track changes to rules alongside changes to the manifests they govern.

How do I handle rules that differ between dev and production?

You can write separate rule files and use glob patterns to target different directories, for example rules/k8s-prod.mdc matching **/k8s/prod/**. The key is to state the environment in the rule title so an assistant reading it knows which cluster the rule applies to.

What if my assistant ignores the rules?

Check that the rule file is in the right directory and that its activation setting is correct. For rules you want applied whenever a Kubernetes file is open, set alwaysApply to true or use the auto-attach glob pattern. The cursor-rules-not-working guide walks through the most common activation failures.

More in Prompts and skills for AI work

All Prompts and skills for AI work articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.