Skip to content

project rulesDevOps and cloudkubernetes

Kubernetes Rules

Project rules for Kubernetes manifests: standard labels, resource requests, probes, restricted security contexts, config handling and safe rollouts.

npx workspacetemplates add kubernetes-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file20 lines · 1.4 KBFile
# Project rules: Kubernetes

## Metadata
- Put every object in an explicit namespace and give it the `app.kubernetes.io/name`, `instance`, `version` and `part-of` labels. Selectors use only stable labels, never the version.
- Pin images to a version or digest, never `latest`. Set `imagePullPolicy` on purpose.

## Resources and probes
- Set CPU and memory `requests` on every container, and a memory `limit` equal to or above the request. Be careful with CPU limits that throttle.
- Define `readinessProbe` for traffic, `livenessProbe` only for real deadlocks, and `startupProbe` for slow starts. Handle `SIGTERM` and set a `terminationGracePeriodSeconds` that fits.

## Security
- Set `runAsNonRoot: true`, `allowPrivilegeEscalation: false`, `readOnlyRootFilesystem: true`, drop all capabilities and use the `RuntimeDefault` seccomp profile. Do not use `hostNetwork` or privileged mode.
- Give each workload its own ServiceAccount with minimal RBAC, and add a NetworkPolicy.

## Config and rollout
- Use ConfigMaps for settings and Secrets, or an external secrets operator, for credentials. Never put secrets in manifests in git.
- Run at least two replicas for services, with a PodDisruptionBudget and topology spread. Use `RollingUpdate` with `maxUnavailable: 0` for critical services. Add an HPA when load varies.

## Validate
- Run `kubectl apply --dry-run=server`, `kubeconform` and `kube-linter lint` (or Polaris) and review the `kubectl diff`.

What it does

A manifest that applies cleanly can still be unsafe or fragile in a real cluster. These rules guide an agent toward workloads that can be scheduled fairly, restarted safely and locked down by default.

They also say how configuration, secrets and rollouts should be written, and which commands validate a change before it reaches a cluster.

Example

you › Write manifests to run our API with three replicas behind a Service

agent › The agent writes a Deployment with probes, requests, a restricted security context and spread rules, a Service, a PodDisruptionBudget and an HPA, then validates them with kubeconform and a server dry run.

Questions

Does it prefer Helm or Kustomize?
Neither. The rules are about the rendered objects, so they hold for plain YAML, Helm charts and Kustomize overlays.
Why avoid CPU limits?
They can throttle a process that has spare node capacity. Requests give fair scheduling; add limits only when you need to cap usage.
  • AWS CDK Rules

    Project rulesaws

    Free
  • Docker Rules

    Project rulesdocker

    Free
  • GitHub Actions Rules

    Project rulesgithub-actions

    Free
  • Serverless Lambda Rules

    Project rulesaws

    Free