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.4metadata:5 category: user-invoked6disable-model-invocation: true7---89Default 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.1011# Kubernetes Operations1213## Current Versions (Verify Before Use)1415```bash16kubectl version --client # kubectl version17kubectl version # client + server versions18helm version # Helm version19```2021Check [Kubernetes releases](https://kubernetes.io/releases/) for the latest stable and [Helm releases](https://github.com/helm/helm/releases).2223## Core Principles24251. **Declarative over imperative.** Use YAML manifests and `kubectl apply`. Avoid `kubectl run`, `kubectl create` for production.262. **GitOps is the default.** Every manifest change goes through version control and automated sync (ArgoCD, Flux, or similar).273. **Resource limits are mandatory.** Every container must have `requests` and `limits` for CPU and memory.284. **Health probes are mandatory.** Every container must have `livenessProbe` and `readinessProbe`.295. **Least privilege RBAC.** Every ServiceAccount has the minimum permissions required.3031## Manifest Review Checklist3233### Deployment / Pod Spec34- [ ] Resource `requests` and `limits` defined for all containers35- [ ] `livenessProbe` and `readinessProbe` defined36- [ ] `securityContext` sets `runAsNonRoot: true`, `readOnlyRootFilesystem: true` where possible37- [ ] `imagePullPolicy: Always` or pinned image digest (no implicit `IfNotPresent` with `latest`)38- [ ] `replicas` appropriate for the workload (not hardcoded to 1 for stateless services)39- [ ] `strategy` defined for rolling updates (`RollingUpdate` with `maxUnavailable`/`maxSurge`)4041### Service / Ingress42- [ ] Service selector matches Deployment labels exactly43- [ ] Ingress has TLS configured (no plaintext HTTP in production)44- [ ] Ingress paths don't overlap ambiguously45- [ ] Backend service port matches container port4647### Config / Secrets48- [ ] Secrets are base64-encoded (not plaintext in YAML)49- [ ] ConfigMaps don't contain sensitive data (use Secrets)50- [ ] Environment variables reference ConfigMaps/Secrets via `valueFrom` (not hardcoded)5152### RBAC53- [ ] Role/ClusterRole has explicit verbs and resources (no wildcard `*`)54- [ ] ServiceAccount is explicitly defined (not default)55- [ ] Bindings are scoped to namespaces where possible5657## Validation Commands5859```bash60# Dry-run before apply61kubectl apply -f manifest.yaml --dry-run=server6263# Validate with strict schema64kubectl apply -f manifest.yaml --dry-run=server --validate=strict6566# Check resource usage vs limits67kubectl top pods -n <namespace>68kubectl describe node <node-name>6970# Audit security posture71kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>7273# Helm validation74helm lint ./chart75helm template ./chart | kubectl apply --dry-run=server -f -76helm install --dry-run --debug release-name ./chart77```7879## Resource Limits Template8081```yaml82resources:83 requests:84 memory: "128Mi"85 cpu: "100m"86 limits:87 memory: "256Mi"88 cpu: "500m"89```9091**Rules of thumb:**92- `requests` = observed steady-state usage + 20%93- `limits` = observed peak usage + 50%94- Memory limits are hard limits (OOMKill at limit)95- CPU limits are throttled, not killed9697## Health Probe Patterns9899```yaml100livenessProbe:101 httpGet:102 path: /health/live103 port: 8080104 initialDelaySeconds: 10105 periodSeconds: 10106 failureThreshold: 3107108readinessProbe:109 httpGet:110 path: /health/ready111 port: 8080112 initialDelaySeconds: 5113 periodSeconds: 5114```115116- **Liveness:** Is the process alive? If failing, kubelet restarts the container.117- **Readiness:** Is the pod ready to serve traffic? If failing, pod is removed from Service endpoints.118- **Startup:** For slow-starting apps. Disables liveness/readiness until complete.119120## Common Anti-Patterns121122| Anti-Pattern | Why It's Wrong | Fix |123|---|---|---|124| No resource limits | Noisy neighbor, unpredictable OOMKills | Set `requests` and `limits` |125| `image: myapp:latest` | Non-reproducible deployments | Pin to digest or version tag |126| Running as root | Container escape risk | `securityContext.runAsNonRoot: true` |127| No health probes | Failed containers stay in rotation | `livenessProbe` + `readinessProbe` |128| Wildcard RBAC (`verbs: ["*"]`) | Principle of least privilege violation | Explicit verbs per resource |129| Hardcoding config in YAML | No environment separation | ConfigMaps + Secrets |130| Using default ServiceAccount | No audit trail, overprivileged | Explicit SA per workload |131| No PodDisruptionBudget | Voluntary disruptions cause downtime | Define `minAvailable` or `maxUnavailable` |132133## Troubleshooting Flow1341351. **Pod stuck Pending:** `kubectl describe pod` → check node resources, taints, PVC binding1362. **Pod CrashLoopBackOff:** `kubectl logs --previous` → check exit code, OOMKilled, application error1373. **Service not reachable:** Check selector match, endpoints (`kubectl get endpoints`), port alignment1384. **Ingress 502/503:** Check backend health, readiness probe, Service port1395. **High memory usage:** `kubectl top pod` → check limits, consider HPA or VPA1406. **RBAC denied:** `kubectl auth can-i <verb> <resource> --as=system:serviceaccount:<ns>:<sa>`141142## Helm Best Practices143144```yaml145# Chart.yaml146apiVersion: v2147name: myapp148description: A Helm chart for myapp149type: application150version: 1.0.0151appVersion: "2.0.0"152```153154- Use `helm lint` in CI155- Template with `helm template` and pipe to `kubectl apply --dry-run=server`156- Store values per environment (`values-prod.yaml`, `values-staging.yaml`)157- Don't put secrets in `values.yaml` — use external secret operators158159## Official Resources160161- [Kubernetes API reference](https://kubernetes.io/docs/reference/kubernetes-api/)162- [kubectl cheat sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)163- [Helm docs](https://helm.sh/docs/)164- [Pod Security Standards](https://kubernetes.io/docs/concepts/security/pod-security-standards/)165- [RBAC docs](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)