---
name: kubernetes-manifest-review
description: Reviews Kubernetes manifests and Helm values for reliability and security: resources, probes, securityContext, image tags, PodDisruptionBudget, rollout strategy. Use when the user writes, edits or asks to review K8s YAML, a Helm chart or a deployment.
---

# Kubernetes Manifest Review

Review Deployments, StatefulSets, Services, Ingresses and Helm values for production readiness. Read all manifests of the app together (workload, service, config, PDB, HPA, network policy) before judging any one of them.

## Workflow

1. Locate manifests (`k8s/`, `deploy/`, `charts/`, kustomize overlays). If Helm, render first: `helm template <release> <chart> -f values.yaml`.
2. Run through the checklist and note each finding with `kind/name`, field path and severity.
3. Fix with minimal edits that keep the existing structure (kustomize patches, values keys).
4. Verify against the cluster in read-only mode (see Verification). Never `kubectl apply` or `delete` without the user's explicit confirmation, and confirm which cluster and namespace the current context points to.

## Checklist

### Image
- Tag is a specific version or digest, never `latest` or an omitted tag.
- `imagePullPolicy` matches: `IfNotPresent` for immutable tags, `Always` only if tags are mutable.
- `imagePullSecrets` set for private registries.

### Resources
- Every container has `resources.requests` for cpu and memory, and a memory `limits` value. Treat a CPU limit as optional and discuss throttling with the user before adding one.
- Memory request should be close to the limit for predictable scheduling; check the numbers against actual usage if metrics are available (`kubectl top pod`).
- Set the JVM/Node heap flags relative to the memory limit.

### Probes
- `readinessProbe` gates traffic; `livenessProbe` restarts stuck processes; `startupProbe` protects slow starts.
- Liveness must not depend on external services (database, other pods), otherwise an outage causes a restart storm.
- Set sensible `initialDelaySeconds`, `periodSeconds`, `timeoutSeconds`, `failureThreshold`. Probe paths must exist in the app.

### securityContext
- Pod level: `runAsNonRoot: true`, `runAsUser` numeric, `seccompProfile: {type: RuntimeDefault}`, `fsGroup` if volumes are written.
- Container level: `allowPrivilegeEscalation: false`, `readOnlyRootFilesystem: true` (add `emptyDir` mounts for `/tmp` and cache dirs), `capabilities: {drop: ["ALL"]}`.
- No `privileged: true`, `hostNetwork`, `hostPath` unless the user explains why.
- `automountServiceAccountToken: false` when the pod does not call the API; use a dedicated ServiceAccount.

### Availability and rollout
- `replicas >= 2` for anything user-facing; spread with `topologySpreadConstraints` or pod anti-affinity.
- Add a `PodDisruptionBudget` (`minAvailable` or `maxUnavailable`) so node drains do not take the service down.
- Deployment strategy: `RollingUpdate` with `maxUnavailable: 0` and `maxSurge: 1` for zero-downtime; `minReadySeconds` if needed. StatefulSets need an update strategy that fits the data store.
- Add a `preStop` sleep and `terminationGracePeriodSeconds` long enough to drain connections.
- HPA targets must reference requests that exist.

### Config and secrets
- Secrets come from `Secret` objects or an external secret operator, not plain `env: value:` in the manifest.
- Never put secret values into ConfigMaps, Helm values committed to git, or labels/annotations.
- Mount config as files or use `envFrom`; changing a ConfigMap does not restart pods by itself, so check for a checksum annotation or reloader.

### Networking and labels
- Service selector matches pod labels exactly; ports and `targetPort` names line up.
- Consistent `app.kubernetes.io/*` labels. A `NetworkPolicy` exists when the cluster enforces them.
- Ingress has TLS and a sensible body-size/timeout configuration where the controller needs one.

## Verification

```bash
kubectl config current-context
kubectl diff -f manifest.yaml                      # read-only, shows what would change
kubectl apply --dry-run=server -f manifest.yaml    # schema and admission check
kubectl auth can-i create deployments -n <ns>
helm lint ./chart && helm template r ./chart | kubectl apply --dry-run=server -f -
```

If `kubeconform`, `kube-linter` or `kubescape` are installed, run them and include the output summary.

## Output format

Report:
1. Findings table: `severity | resource | field | problem | recommended change`.
2. The edited manifests or a diff.
3. Results of diff and dry-run, with the cluster context used.
4. Open questions for the user (real resource usage, expected traffic, compliance needs).

## Pitfalls

- Do not add a CPU limit or tight memory limit blindly; it can cause throttling or OOM kills. Ask for real usage data.
- `readOnlyRootFilesystem` breaks apps that write to disk; test it and add writable volumes.
- Do not change `selector` of an existing Deployment; the field is immutable.
- Do not rename PVCs or StatefulSet volume templates; that orphans data.
- Never run `kubectl delete`, `scale 0` or `rollout restart` on a shared cluster without confirmation.

Source: [AnyModel skills catalog](https://anymodel.org/en/skills) · License: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
