Default output: return only the result, blockers, and required evidence. Omit preambles, process narration, repeated context, confidence scores, and follow-up offers. Use at most five bullets unless a required artifact or schema needs more.
Kubernetes Operations
Current Versions (Verify Before Use)
kubectl version --client # kubectl version
kubectl version # client + server versions
helm version # Helm version
Check Kubernetes releases for the latest stable and Helm releases.
Core Principles
- Declarative over imperative. Use YAML manifests and
kubectl apply. Avoid kubectl run, kubectl create for production.
- GitOps is the default. Every manifest change goes through version control and automated sync (ArgoCD, Flux, or similar).
- Resource limits are mandatory. Every container must have
requests and limits for CPU and memory.
- Health probes are mandatory. Every container must have
livenessProbe and readinessProbe.
- Least privilege RBAC. Every ServiceAccount has the minimum permissions required.
Manifest Review Checklist
Deployment / Pod Spec
Service / Ingress
Config / Secrets
RBAC
Validation Commands
# Dry-run before apply
kubectl apply -f manifest.yaml --dry-run=server
# Validate with strict schema
kubectl apply -f manifest.yaml --dry-run=server --validate=strict
# Check resource usage vs limits
kubectl top pods -n <namespace>
kubectl describe node <node-name>
# Audit security posture
kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>
# Helm validation
helm lint ./chart
helm template ./chart | kubectl apply --dry-run=server -f -
helm install --dry-run --debug release-name ./chart
Resource Limits Template
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
Rules of thumb:
requests = observed steady-state usage + 20%
limits = observed peak usage + 50%
- Memory limits are hard limits (OOMKill at limit)
- CPU limits are throttled, not killed
Health Probe Patterns
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
- Liveness: Is the process alive? If failing, kubelet restarts the container.
- Readiness: Is the pod ready to serve traffic? If failing, pod is removed from Service endpoints.
- Startup: For slow-starting apps. Disables liveness/readiness until complete.
Common Anti-Patterns
| Anti-Pattern |
Why It's Wrong |
Fix |
| No resource limits |
Noisy neighbor, unpredictable OOMKills |
Set requests and limits |
image: myapp:latest |
Non-reproducible deployments |
Pin to digest or version tag |
| Running as root |
Container escape risk |
securityContext.runAsNonRoot: true |
| No health probes |
Failed containers stay in rotation |
livenessProbe + readinessProbe |
Wildcard RBAC (verbs: ["*"]) |
Principle of least privilege violation |
Explicit verbs per resource |
| Hardcoding config in YAML |
No environment separation |
ConfigMaps + Secrets |
| Using default ServiceAccount |
No audit trail, overprivileged |
Explicit SA per workload |
| No PodDisruptionBudget |
Voluntary disruptions cause downtime |
Define minAvailable or maxUnavailable |
Troubleshooting Flow
- Pod stuck Pending:
kubectl describe pod → check node resources, taints, PVC binding
- Pod CrashLoopBackOff:
kubectl logs --previous → check exit code, OOMKilled, application error
- Service not reachable: Check selector match, endpoints (
kubectl get endpoints), port alignment
- Ingress 502/503: Check backend health, readiness probe, Service port
- High memory usage:
kubectl top pod → check limits, consider HPA or VPA
- RBAC denied:
kubectl auth can-i <verb> <resource> --as=system:serviceaccount:<ns>:<sa>
Helm Best Practices
# Chart.yaml
apiVersion: v2
name: myapp
description: A Helm chart for myapp
type: application
version: 1.0.0
appVersion: "2.0.0"
- Use
helm lint in CI
- Template with
helm template and pipe to kubectl apply --dry-run=server
- Store values per environment (
values-prod.yaml, values-staging.yaml)
- Don't put secrets in
values.yaml — use external secret operators
Official Resources
1---2name: k8s3description: Deploy, manage, and troubleshoot Kubernetes workloads. Use for manifest review, Helm chart validation, resource tuning, RBAC, and cluster operations.4---56Default output: return only the result, blockers, and required evidence. Omit preambles, process narration, repeated context, confidence scores, and follow-up offers. Use at most five bullets unless a required artifact or schema needs more.78# Kubernetes Operations910## Current Versions (Verify Before Use)1112```bash13kubectl version --client # kubectl version14kubectl version # client + server versions15helm version # Helm version16```1718Check [Kubernetes releases](https://kubernetes.io/releases/) for the latest stable and [Helm releases](https://github.com/helm/helm/releases).1920## Core Principles21221. **Declarative over imperative.** Use YAML manifests and `kubectl apply`. Avoid `kubectl run`, `kubectl create` for production.232. **GitOps is the default.** Every manifest change goes through version control and automated sync (ArgoCD, Flux, or similar).243. **Resource limits are mandatory.** Every container must have `requests` and `limits` for CPU and memory.254. **Health probes are mandatory.** Every container must have `livenessProbe` and `readinessProbe`.265. **Least privilege RBAC.** Every ServiceAccount has the minimum permissions required.2728## Manifest Review Checklist2930### Deployment / Pod Spec31- [ ] Resource `requests` and `limits` defined for all containers32- [ ] `livenessProbe` and `readinessProbe` defined33- [ ] `securityContext` sets `runAsNonRoot: true`, `readOnlyRootFilesystem: true` where possible34- [ ] `imagePullPolicy: Always` or pinned image digest (no implicit `IfNotPresent` with `latest`)35- [ ] `replicas` appropriate for the workload (not hardcoded to 1 for stateless services)36- [ ] `strategy` defined for rolling updates (`RollingUpdate` with `maxUnavailable`/`maxSurge`)3738### Service / Ingress39- [ ] Service selector matches Deployment labels exactly40- [ ] Ingress has TLS configured (no plaintext HTTP in production)41- [ ] Ingress paths don't overlap ambiguously42- [ ] Backend service port matches container port4344### Config / Secrets45- [ ] Secrets are base64-encoded (not plaintext in YAML)46- [ ] ConfigMaps don't contain sensitive data (use Secrets)47- [ ] Environment variables reference ConfigMaps/Secrets via `valueFrom` (not hardcoded)4849### RBAC50- [ ] Role/ClusterRole has explicit verbs and resources (no wildcard `*`)51- [ ] ServiceAccount is explicitly defined (not default)52- [ ] Bindings are scoped to namespaces where possible5354## Validation Commands5556```bash57# Dry-run before apply58kubectl apply -f manifest.yaml --dry-run=server5960# Validate with strict schema61kubectl apply -f manifest.yaml --dry-run=server --validate=strict6263# Check resource usage vs limits64kubectl top pods -n <namespace>65kubectl describe node <node-name>6667# Audit security posture68kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>6970# Helm validation71helm lint ./chart72helm template ./chart | kubectl apply --dry-run=server -f -73helm install --dry-run --debug release-name ./chart74```7576## Resource Limits Template7778```yaml79resources:80 requests:81 memory: "128Mi"82 cpu: "100m"83 limits:84 memory: "256Mi"85 cpu: "500m"86```8788**Rules of thumb:**89- `requests` = observed steady-state usage + 20%90- `limits` = observed peak usage + 50%91- Memory limits are hard limits (OOMKill at limit)92- CPU limits are throttled, not killed9394## Health Probe Patterns9596```yaml97livenessProbe:98 httpGet:99 path: /health/live100 port: 8080101 initialDelaySeconds: 10102 periodSeconds: 10103 failureThreshold: 3104105readinessProbe:106 httpGet:107 path: /health/ready108 port: 8080109 initialDelaySeconds: 5110 periodSeconds: 5111```112113- **Liveness:** Is the process alive? If failing, kubelet restarts the container.114- **Readiness:** Is the pod ready to serve traffic? If failing, pod is removed from Service endpoints.115- **Startup:** For slow-starting apps. Disables liveness/readiness until complete.116117## Common Anti-Patterns118119| Anti-Pattern | Why It's Wrong | Fix |120|---|---|---|121| No resource limits | Noisy neighbor, unpredictable OOMKills | Set `requests` and `limits` |122| `image: myapp:latest` | Non-reproducible deployments | Pin to digest or version tag |123| Running as root | Container escape risk | `securityContext.runAsNonRoot: true` |124| No health probes | Failed containers stay in rotation | `livenessProbe` + `readinessProbe` |125| Wildcard RBAC (`verbs: ["*"]`) | Principle of least privilege violation | Explicit verbs per resource |126| Hardcoding config in YAML | No environment separation | ConfigMaps + Secrets |127| Using default ServiceAccount | No audit trail, overprivileged | Explicit SA per workload |128| No PodDisruptionBudget | Voluntary disruptions cause downtime | Define `minAvailable` or `maxUnavailable` |129130## Troubleshooting Flow1311321. **Pod stuck Pending:** `kubectl describe pod` → check node resources, taints, PVC binding1332. **Pod CrashLoopBackOff:** `kubectl logs --previous` → check exit code, OOMKilled, application error1343. **Service not reachable:** Check selector match, endpoints (`kubectl get endpoints`), port alignment1354. **Ingress 502/503:** Check backend health, readiness probe, Service port1365. **High memory usage:** `kubectl top pod` → check limits, consider HPA or VPA1376. **RBAC denied:** `kubectl auth can-i <verb> <resource> --as=system:serviceaccount:<ns>:<sa>`138139## Helm Best Practices140141```yaml142# Chart.yaml143apiVersion: v2144name: myapp145description: A Helm chart for myapp146type: application147version: 1.0.0148appVersion: "2.0.0"149```150151- Use `helm lint` in CI152- Template with `helm template` and pipe to `kubectl apply --dry-run=server`153- Store values per environment (`values-prod.yaml`, `values-staging.yaml`)154- Don't put secrets in `values.yaml` — use external secret operators155156## Official Resources157158- [Kubernetes API reference](https://kubernetes.io/docs/reference/kubernetes-api/)159- [kubectl cheat sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)160- [Helm docs](https://helm.sh/docs/)161- [Pod Security Standards](https://kubernetes.io/docs/concepts/security/pod-security-standards/)162- [RBAC docs](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)