Kubernetes Best Practices
Deployment Strategies
- Use
DeploymentwithRollingUpdateas default: setmaxSurgeandmaxUnavailablefor controlled rollouts - Implement
readinessProbeandlivenessProbeon every container -- HTTP or exec-based - Use
startupProbefor slow-starting applications to prevent premature kill by the liveness probe - Set resource
requestsandlimitson every pod: CPU/Memory requests for scheduling, limits for QoS - Apply
PodDisruptionBudgetto maintain availability during voluntary disruptions (node drains, upgrades)
Service Mesh
- Use a service mesh (Istio, Linkerd) for mTLS, traffic shaping, and observability when microservices exceed ~10
- Define
DestinationRulefor circuit breaking and connection pooling - Use
VirtualServicefor canary deployments: route percentages between service versions - Apply
PeerAuthenticationfor strict mTLS mode across the mesh - Keep mesh configuration in the same repository as the application manifests
Helm Charts
- Structure charts with
templates/,values.yaml,Chart.yaml, andREADME.md - Use
values.yamlfor environment-agnostic defaults; override with-f staging.yamlper environment - Template with
{{ .Values.* }}and{{ .Release.* }}; use{{-to trim whitespace - Use named templates (
_helpers.tpl) for reusable label blocks and common metadata - Run
helm lintandhelm templatein CI; usehelm testfor release validation hooks
RBAC and Security
- Apply least-privilege RBAC: create
Role/RoleBindingper namespace, avoidClusterRoleunless necessary - Use
NetworkPolicyto restrict pod-to-pod traffic: default deny, explicitly allow required flows - Run containers as non-root: set
runAsNonRoot: true,readOnlyRootFilesystem: truein security contexts - Use
SealedSecretsor external secret managers (Vault, AWS Secrets Manager) -- never plaintext secrets - Scan images with Trivy or Grype in CI; enforce admission controllers to block vulnerable images
Autoscaling and GitOps
- Configure
HorizontalPodAutoscalerwith CPU/memory and custom metrics via Prometheus adapter - Use
VerticalPodAutoscalerfor right-sizing requests in steady-state workloads - Implement GitOps with ArgoCD or Flux: declarative repo -> automated cluster reconciliation
- Structure repos as
clusters/,apps/,infra/for GitOps clarity; use app-of-apps pattern in ArgoCD - Use
Kustomizeoverlays for environment-specific patches without duplicating base manifests
Source: calcosmic/Aether — distributed by TomeVault.