Kubernetes, Monitoring ও Production Checklist

লেসন ৩৮ / ৩৮

☸️ Kubernetes কেন?

  • Container orchestration at scale
  • Auto-healing, auto-scaling, rolling update
  • Declarative — desired state maintain
  • Multi-cloud portable
  • 100s of service = K8s, 1-5 service = Docker Compose যথেষ্ট

🏗️ Core Objects

Pod       — smallest unit (1+ container)
Deployment — manage ReplicaSet + Pod
Service   — stable network endpoint
Ingress   — HTTP routing + SSL
ConfigMap — config data
Secret    — sensitive data
Namespace — logical isolation
PV/PVC    — persistent storage

📝 Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata: {name: myapp}
spec:
  replicas: 3
  selector:
    matchLabels: {app: myapp}
  template:
    metadata:
      labels: {app: myapp}
    spec:
      containers:
      - name: web
        image: myapp:1.0
        ports: [{containerPort: 3000}]
        resources:
          limits: {cpu: 500m, memory: 512Mi}
        livenessProbe:
          httpGet: {path: /health, port: 3000}
          initialDelaySeconds: 30
---
apiVersion: v1
kind: Service
metadata: {name: myapp-svc}
spec:
  selector: {app: myapp}
  ports: [{port: 80, targetPort: 3000}]
  type: LoadBalancer

🎯 kubectl Commands

kubectl apply -f deployment.yaml
kubectl get pods
kubectl get deployments
kubectl describe pod 
kubectl logs -f 
kubectl exec -it  -- sh
kubectl scale deployment myapp --replicas=5
kubectl rollout restart deployment/myapp
kubectl rollout undo deployment/myapp
kubectl delete -f deployment.yaml

🛠️ Managed K8s

  • AWS EKS — $0.10/hr cluster
  • GKE — best UX, Autopilot mode
  • AKS — Azure
  • DigitalOcean K8s — cheap
  • k3s — lightweight, single-node OK

⛵ Helm (K8s Package Manager)

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-nginx bitnami/nginx
helm list
helm upgrade my-nginx bitnami/nginx
helm rollback my-nginx 1

# Create own chart
helm create myapp

📊 Monitoring Stack

Prometheus + Grafana

Prometheus: time-series metric database, scrapes /metrics
Grafana: visualization, alerting

# Helm install
helm install monitor prometheus-community/kube-prometheus-stack

# Access Grafana
kubectl port-forward svc/monitor-grafana 3000:80
# Default: admin / prom-operator

Key Metrics

CPU/Memory usage
Request rate (RPS)
Error rate (4xx, 5xx %)
Latency (p50, p95, p99)
Pod restart count
Disk I/O, Network
DB connection pool

📜 Centralized Logging

ELK Stack

Elasticsearch — search/store
Logstash — process/transform
Kibana — visualize
Filebeat — ship logs

# Modern alternative: Loki + Grafana (cheaper)

🚨 Alerting

# Alertmanager rules
- alert: HighErrorRate
  expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.05
  for: 5m
  annotations:
    summary: "High 5xx error rate"

# Destinations
- PagerDuty (on-call)
- Slack / Discord
- Email
- Opsgenie

🎯 SLI / SLO / SLA

  • SLI — measured indicator (uptime %)
  • SLO — internal target (99.9%)
  • SLA — customer promise (99.5%)
  • Error budget = 1 - SLO (how much breakage allowed)

💥 Disaster Recovery

RTO — Recovery Time Objective (how fast)
RPO — Recovery Point Objective (how much data loss OK)

Strategies (cost ↑, RTO ↓):
- Backup & restore (hours)
- Pilot Light (minutes)
- Warm Standby (seconds)
- Hot Active-Active (instant)

# Drill quarterly — untested plan = no plan

✅ Production Checklist

Infrastructure

  • Multi-AZ/region deployment
  • Auto-scaling configured
  • Load balancer + health check
  • CDN (CloudFront/Cloudflare)
  • DDoS protection
  • WAF rules

Security

  • SSL/TLS everywhere (HSTS)
  • Secret manager (no .env in repo)
  • IAM least privilege
  • MFA all admin users
  • Security group restrictive
  • DB not publicly accessible
  • Image vulnerability scan in CI
  • Regular penetration test
  • SOC2/ISO compliance if required

Reliability

  • Health check endpoint
  • Graceful shutdown
  • Circuit breaker for external calls
  • Retry + backoff
  • Timeout everywhere
  • Rate limiting
  • Queue for async work

Observability

  • Structured logging (JSON)
  • Distributed tracing (OpenTelemetry)
  • Metrics + dashboard
  • Alerting on SLO breach
  • On-call rotation
  • Runbook for common issues

Operations

  • CI/CD automated
  • Blue/green or canary deploy
  • Rollback 1-click
  • Database migration reversible
  • Backup daily + tested restore
  • DR plan documented + drilled
  • Post-mortem culture

Performance

  • CDN caching
  • DB query optimize + index
  • Redis cache hot data
  • Image optimization (WebP, lazy)
  • Gzip/Brotli compression
  • Load test before launch

💎 Cost Optimization

  • Right-size instances
  • Reserved/Savings Plan for steady
  • Spot for fault-tolerant
  • S3 lifecycle to Glacier
  • Delete unused (EBS, EIP, snapshot, logs)
  • Stop dev night
  • CDN reduce origin bandwidth
  • AWS Cost Explorer monthly review

🎓 মূল কথা ⭐ — Final

Production readiness = security + reliability + observability + DR + cost। Kubernetes overkill for small team (Docker Compose যথেষ্ট)। Monitor everything, alert on symptoms not cause। Untested backup = no backup। Incident postmortem = culture। DevOps journey continuous — Domain থেকে Cloud পর্যন্ত আপনি এখন ready। 🚀