Kubernetes Best Practices
Workload configuration
Pod resource management
- Always set resource requests AND limits
- Use
resources.requestsfor scheduling,resources.limitsfor throttling - Start conservative and tune based on metrics
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
Health checks
- livenessProbe — restart if unhealthy (use for deadlock detection)
- readinessProbe — remove from service if not ready (use for startup/dependency checks)
- startupProbe — delay liveness checks during startup (use for slow-starting apps)
Pod disruption budgets
- Always define PDBs for production workloads
minAvailable: 1ormaxUnavailable: 1for small deployments
Troubleshooting
Pod not starting
kubectl describe pod <name>— check Events sectionkubectl logs <name> --previous— check crash logs- Common causes: image pull errors, resource limits, missing secrets
Service not reachable
kubectl get endpoints <service>— verify endpoints existkubectl get pods -l <selector>— check pod readinesskubectl exec -it <pod> -- curl localhost:<port>/health— test from inside
OOMKilled
- Check
kubectl describe podfor last termination reason - Increase memory limits
- Profile the application for memory leaks
Security
- Use NetworkPolicies to restrict pod-to-pod traffic
- Never run containers as root — use
securityContext.runAsNonRoot: true - Use ServiceAccounts with minimal RBAC permissions
- Scan images for vulnerabilities before deploying
Source: jdiegosierra/enterprise-agent-plugins — distributed by TomeVault.