stdsquare²
🎓 Kelas
stdsquare / materi / slides / pertemuan-11
Tema
Japan
Arcade
Dark Retro
Font
‹ Daftar slide Pertemuan 11: Kubernetes Container Orchestration (Pod, Deployment, EKS, Helm)
PEBD6027 · RPS minggu 12 · 2x50 menit

Kubernetes

Container Orchestration · Pod · Deployment · Service · EKS Managed

Peta Pembelajaran Hari Ini

Sub-CPMK 11: menjalankan container di Kubernetes. Empat indikator capaian.

Jam ke-1
  • Mengapa Kubernetes: masalah orchestration
  • Pod, Deployment, Service anatomi
  • kubectl dasar: get, apply, logs
Jam ke-2
  • AWS EKS managed K8s
  • Helm package manager
  • Studi kasus Gojek K8s migration
Posisi 14P: setelah IaC Terraform P10, hari ini Kubernetes. P12 DevOps CI/CD.

Mengapa Kubernetes?

Container solving deployment, TAPI tidak solving orchestration ratusan container dalam produksi. Kubernetes jawab.

Pengguna K8s Fortune 100
~80%
CNCF Survey 2023 — K8s dominant enterprise container orchestrator
Adopsi RI Enterprise
70%+
Survei Indonesia Cloud 2023 (dihedge) — bank digital & startup besar
Container Docker saja tidak cukup untuk produksi: siapa restart bila mati? siapa scale? siapa load balance? K8s solve semua ini.
Bagian 1 · 1/4
K8s Anatomi
Diskusi: bila startup punya 10 microservice, masing-masing butuh 3-5 replica, bagaimana orkestrasi?

Pod, Deployment, Service

Tiga objek fundamental K8s. Pahami sebelum tulis manifest YAML.

Pod
  • Unit terkecil K8s
  • Wrap 1+ container
  • Ephemeral IP & lifecycle
  • Tidak direstart langsung, recreate
Deployment
  • Manage replica Pod
  • Desired state vs actual
  • Rolling update strategy
  • Self-healing bila Pod mati
Service
  • Stable network endpoint
  • Load balance antar Pod
  • Type: ClusterIP, NodePort, LoadBalancer
  • Route traffic via label selector
Analogi: Pod = pekerja, Deployment = manajer jaga pekerja tetap ada, Service = nomor telepon tetap padahal pekerja ganti.

Manifest YAML Anatomi

Manifest = deklarasi desired state K8s. YAML structured dengan apiVersion, kind, metadata, spec.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
      - name: nginx
        image: nginx:1.25
        ports: [{ containerPort: 80 }]
Field Wajib
  • apiVersion: apps/v1 (kind-specific)
  • kind: Deployment, Pod, Service
  • metadata.name: unik dalam namespace
  • spec: konfigurasi objek
Best Practice
  • Label konsisten: app, env, version
  • Resource request & limit wajib
  • Liveness & readiness probe
  • Image tag spesifik, jangan latest
Anti-pattern: image: latest di produksi. Pin tag spesifik untuk reproducibility dan rollback.

Studi Kasus: Gojek Migrasi ke K8s

Gojek migrasi microservice dari Apache Mesos ke Kubernetes untuk skala 2 juta driver.

Public case study Gojek & AWS: pra-K8s (Mesos Marathon) kompleks, scaling manual, rolling update mahal. Pasca-K8s (EKS multi-cluster multi-region): declarative deployment, auto-scaling HPA, multi-region failover Singapore-Jakarta. Hasil (dihedge): deployment frequency 4x lebih sering, MTTR 60% lebih cepat, infra cost turun 30% via better bin-packing.
Pra-K8s (Mesos)
  • Scaling manual per service
  • Rolling update berhari
  • Multi-region failover sulit
  • Resource waste ~40%
Pasca-K8s (EKS)
  • HPA auto-scaling CPU/metric
  • Rolling update menit
  • Multi-region via federation
  • Bin-packing hemat 30%
Pelajaran Bisdig: K8s bukan teknis semata. Time-to-market cepat = keunggulan kompetitif Gojek.

Hitung dari Nol: ROI K8s untuk Microservice

Startup punya 10 microservice, 5 replica each. Manual vs K8s: berapa saving engineer time?

AktivitasManual/scriptK8s
Restart Pod matiManual 5-10 mnt/PodOtomatis <30 dtk
Scale up traffic spikeProvision instance 15-30 mntHPA <1 mnt otomatis
Rolling updateDowntime atau script rumitZero downtime native
Health checkManual cron scriptLiveness probe native
Multi-region failoverDNS + manualService mesh otomatis
Total engineer jam/minggu~20-40 jam~5-10 jam
Saving FTE~0,5-1 FTE ($50K/tahun)
K8s hemat 0,5-1 FTE per 10 microservice. Untuk 50 microservice (enterprise), hemat 2-5 FTE.
Bagian 2 · 2/4
kubectl & Operasional
Diskusi: bila Pod CrashLoopBackOff di produksi, bagaimana debugging step?

kubectl Command Cheat Sheet

Command-line tool untuk interact dengan K8s cluster. Wajib kuasai dasar.

CommandFungsiFrekuensi Pakai
kubectl get podsList Pod dengan statusSangat sering
kubectl get allList semua resource namespaceSering
kubectl describe pod NAMEDetail event & spec PodDebug
kubectl logs NAMEStdout containerDebug
kubectl apply -f FILEApply manifest YAMLDeploy
kubectl delete -f FILEHapus resource dari manifestCleanup
kubectl exec -it NAME -- shShell interaktif PodDebug advanced
kubectl scale deploy NAME --replicas=5Manual scale DeploymentOps
kubectl rollout restart deploy NAMETrigger rolling updateDeploy
kubectl port-forward svc/NAME 8080:80Akses Service lokalDebug lokal
Hafal 10 command ini. 80% operasional K8s sehari-hari pakai command ini.

Namespace & Resource Quota

Namespace = virtual cluster dalam 1 K8s cluster. Resource quota = limit per namespace.

Namespace
  • Isolasi tim atau env
  • Contoh: dev, staging, prod
  • RBAC scope per namespace
  • Network policy isolate traffic
Resource Quota
  • Limit CPU/memory per namespace
  • Cegah tim nakal hog resource
  • Hard cap untuk cost control
  • Alert bila mendekati limit
Multi-tenant cluster: 1 namespace per tim + resource quota + RBAC + network policy. Pola enterprise.

ConfigMap & Secret

ConfigMap untuk config non-sensitif, Secret untuk sensitif (password, key). Decouple dari image.

ConfigMap
  • Simpan config non-sensitif
  • Database URL, log level
  • Mount sebagai env var atau file
  • Update tanpa rebuild image
Secret
  • Simpan data sensitif
  • Password, API key, cert
  • Base64 encoded (bukan encryption)
  • Encrypt at-rest via etcd encryption
Secret base64 bukan encryption. Wajib enable etcd encryption at-rest. AWS Secrets Manager via CSI driver untuk production.
Bagian 3 · 3/4
EKS & Helm
Diskusi: bila startup RI baru mau pakai K8s, pilih self-managed atau EKS managed?

AWS EKS Managed Kubernetes

EKS = managed Kubernetes di AWS. AWS handle control plane, Anda fokus worker node & workload.

Yang AWS Handle
  • Control plane HA multi-AZ
  • Kubernetes version upgrade
  • etcd backup & restore
  • API server scaling
Yang Anda Handle
  • Worker node (EC2, Fargate)
  • Pod scheduling & resource
  • Ingress controller
  • Monitoring & logging
EKS cost: $0,10/jam per cluster (~$73/bln) + worker node. Fargate serverless: bayar per Pod.

Helm Package Manager

Helm = NPM/Yum untuk Kubernetes. Package aplikasi sebagai Chart reusable.

Konsep
  • Chart = package K8s app
  • values.yaml untuk konfigurasi
  • Template YAML dengan variable
  • Repo publik: hub.helm.sh
Manfaat
  • Reuse aplikasi complex
  • Version & rollback mudah
  • Customize via values.yaml
  • Share ke tim / community
Helm solve DRY untuk K8s manifest. Deploy aplikasi 1 command: helm install my-app ./chart.

Ingress & Load Balancing

Ingress = entry point HTTP/HTTPS ke service K8s. AWS Load Balancer Controller untuk EKS.

Ingress Controller
  • Nginx Ingress (populer)
  • AWS Load Balancer Controller (ALB)
  • Traefik, HAProxy alternatif
  • TLS termination via cert-manager
Ingress Resource
  • Route domain ke Service
  • Path-based routing
  • Host-based multi-tenant
  • Annotation control behavior
EKS: AWS Load Balancer Controller auto-provision ALB/NLB bila Ingress dibuat. Integrasi native dengan AWS.
Bagian 4 · 4/4
Best Practice & Penutup
Diskusi: bila startup baru, kapan harus pindah dari docker-compose ke Kubernetes?

K8s Best Practice Production

Standard emas production K8s. Checklist wajib sebelum live.

AspekBest Practice
ImagePin tag spesifik, scan vulnerability (Trivy)
Resourcerequest & limit CPU/memory wajib
HealthLiveness & readiness probe
ConfigConfigMap & Secret (jangan hardcoded)
SecurityRBAC, network policy, non-root user
LoggingCentralized (Fluent Bit + CloudWatch/Loki)
MonitoringPrometheus + Grafana atau CloudWatch Container Insights
Backupetcd backup, Velero untuk PV
Multi-AZPod anti-affinity untuk HA
Auto-scalingHPA (CPU) + Cluster Autoscaler
Tanpa resource request/limit, 1 Pod nakal bisa crash cluster. Tanpa probe, K8s tidak tahu Pod healthy.

Service Mesh: Istio & Linkerd

Service mesh = layer untuk manage service-to-service communication. Maturity tinggi.

Fitur
  • mTLS antar service otomatis
  • Traffic splitting (canary)
  • Retry & circuit breaker
  • Observability distributed tracing
Trade-off
  • Complexity tambahan
  • Latency overhead ~1-5 ms
  • Learning curve tinggi
  • Untuk microservice >20
Istio paling populer. Linkerd lebih ringan. Consul Connect alternatif. Belum wajib untuk startup kecil.

Ringkasan Kunci Pertemuan 11

Hari ini Anda menguasai Kubernetes: Pod, Deployment, Service, kubectl, EKS, Helm.

Triad Fundamental
Pod (unit) + Deployment (replica manager) + Service (network).
Operasional
kubectl dasar. Namespace + Resource Quota untuk multi-tenant.
Ekosistem
EKS managed, Helm package, Ingress LB, Service Mesh.

Tiga lensa P11: declarative desired state · self-healing · auto-scaling.

Persiapan P12: DevOps CI/CD. Baca Brikman bab 4 (CDK) & kimrafik DevOps Handbook. Kuis 5 menit soal Pod vs Deployment.