Kubernetes has matured significantly. Here are the best practices that reflect current learnings and capabilities.
Platform Considerations
Managed vs. Self-Managed
- Use managed Kubernetes:
- EKS, GKE, AKS
- Reduced operational burden
- Automatic upgrades
- Integrated tooling
- Self-manage only when:
- Specific compliance needs
- Cost optimization at scale
- Special requirements
Multi-Cluster Strategy
- Why multiple clusters:
- Environment isolation
- Regional deployment
- Blast radius limitation
- Team separation
- Management tools:
- Fleet management
- GitOps across clusters
- Service mesh federation
Resource Management
Right-Sizing
Set appropriate limits:
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"- Best practices:
- Start conservative
- Monitor actual usage
- Use VPA recommendations
- Regular right-sizing reviews
Autoscaling
Horizontal Pod Autoscaler:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
spec:
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70- KEDA for event-driven:
- Queue-based scaling
- Custom metrics
- Scale to zero
Security
Pod Security Standards
Enforce restricted profile:
apiVersion: v1
kind: Namespace
metadata:
labels:
pod-security.kubernetes.io/enforce: restrictedNetwork Policies
Default deny:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes:
- Ingress
- EgressSecrets Management
- External secrets:
- AWS Secrets Manager
- HashiCorp Vault
- External Secrets Operator
Never store secrets in Git.
Deployment Patterns
GitOps
- Standard approach:
- Declarative configs in Git
- ArgoCD or Flux
- Automated sync
- Drift detection
Progressive Delivery
- Argo Rollouts:
- Canary deployments
- Blue-green deployments
- Automatic rollbacks
- Analysis runs
Observability
The Three Pillars
- Metrics:
- Prometheus
- Grafana dashboards
- Custom metrics
- Alerting
- Logs:
- Structured logging
- Central aggregation
- Log-based alerts
- Retention policies
- Traces:
- OpenTelemetry
- Distributed tracing
- Service maps
- Latency analysis
SLO-Based Monitoring
- Define and track:
- Availability targets
- Latency objectives
- Error budgets
- Burn rate alerts
Cost Optimization
Strategies
Cost Visibility
- Tools:
- Kubecost
- OpenCost
- Cloud provider tools
Common Pitfalls
Avoid
Running Kubernetes? We help teams implement and operate production Kubernetes environments.