Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lessons Learned from Migrating E-business Giant...

Lessons Learned from Migrating E-business Giant to Cloud Native

Background
Architecture
Fix “Container Headache”
Workload Management
Workload Predictability
Scalability Verifying & Trouble Shooting
Dance with Upstream

Lei (Harry) Zhang

May 02, 2019
Tweet

More Decks by Lei (Harry) Zhang

Other Decks in Technology

Transcript

  1. CONTENT • Background • Architecture • Fix “Container Headache” •

    Workload Management • Workload Predictability • Scalability Verifying & Trouble Shooting • Dance with Upstream
  2. CONTENT Background • Alibaba began to move its e-business platform

    to cloud in 2019 • Standing on the shoulder of open source: • Kubernetes • Operator Framework • CNI, CSI, CRI, DevicePlugin … • Prometheus • Containerd (Alibaba Pouch distribution) • runC + KataContainers • DevOps framework from ACK • ACK = Alibaba Container Service for Kubernetes • and much more …
  3. Architecture Developer/PaaS/ DevOps system Internal App Mgmt System (Dashboard, Resource

    Planning, Alibaba Singles Day Sale) Search Engine, AD, Logistics, middleware Serverless, 2nd party product, 3rd party system Declarative API/GitOps/Kustomize CRDs + Operators Customized Scheduler (Cerebellum) kube-apiserver Admission Hooks kube-controller-manger Customized Controllers (Kruise) Alibaba ECS Bare Metal Instance kubelet containerd Alibaba ECS Bare Metal Instance kubelet containerd Alibaba ECS Bare Metal Instance kubelet containerd Logging Monitoring Elastic Resource Pool Cloud Provider CNI CSI Aggregator Kubernetes (Alibaba Serverless Infrastructure) Multi-tenancy Add-on
  4. The “Container Headache” • Before 2018 • Java • PID

    1 process is Systemd • ALL in ONE container (“Rich Container”), independent upgrade • app, sshd, log, monitoring, cache, VIP, DNS, proxy, agent, start/stop scripts … • Traditional operating workflow • Start container -> SSH into container -> Start the app • Log files & user data are distributed everywhere in the container • In-house orchestration & scheduling system “Rich Container” Monolithic Java System
  5. Fix “Container Headache” apiVersion: v1 kind: Pod spec: containers: -

    env: - name: ali_start_app value: "no” name: main lifecycle: postStart: exec: command: - /bin/sh - -c - for i in $(seq 1 60); do [ -x /home/admin/.start ] && break ; sleep 5 ; done; sudo -u admin /home/admin/.start>/var/log/kubeapp/start.log 2>&1 && sudo -u admin /home/admin/health.sh>>/var/log/kubeapp/start.log 2>&1 preStop: exec: command: - /bin/sh - -c - sudo -u admin /home/admin/stop.sh>/var/log/kubeapp/stop.log 2>&1 livenessProbe: exec: command: - /bin/sh - -c - sudo -u admin /home/admin/health.sh>/var/log/kubeapp/health.log 2>&1 initialDelaySeconds: 20 periodSeconds: 60 timeoutSeconds: 20 Pod APP Ops Sidecar (agent) Assist Sidecar (cache) Mesh Sidecar (proxy) Live Upgrading Sidecar Shared volume Different resource QoS Fine-grained lifecycle control & health check App start script App stop script Health check
  6. Live Upgrading Sidecar • A sidecar container to perform app

    live upgrading by: 1. Copy WAR/data into shared volume 2. Trigger app container re-load WAR/data • Rely on “In-Place-Upgrade” to rollout sidecar containers • Not out-of-box in Kubernetes, will explain later
  7. Sidecar Operator • When we have thousands sidecars, we’ll need:

    • A SidecarSet CRD: • Describe all sidecars need to be operated • A SidecarOperator: 1. Inject sidecar containers to selected Pods 2. Upgrade sidecar containers following rollout policy when SidecarSet is updated 3. Delete sidecar containers when SidecarSet is deleted Controller Inject Upgrade Delete Admission Hook Pod Pod Pod
  8. Workloads Management • Kubernetes Application = YAML • Kubernetes Workloads

    = Operating Model • StatefulSet • Deployment • Job • CronJob • DaemonSet • Pre-defined models of • Rollout Policy • Instance Recovery • Batch Deploy • Blue-Green Deploy • Canary Deploy • Lessons learned: • They are well defined & convenient; • may not fit to all cases though …
  9. Kruise: Kubernetes Workloads Advanced • A fleet of customized CRD

    + controllers that operate applications at web scale. • Pluggable, repeatable and Kubernetes native (Declarative API + Controller Pattern) • 100 % Open Source (very soon!) kube-apiserver Deployment StatefulSet InplaceSet BroadcastJob Pod Pod Pod Pod Pod Pod Pod Pod
  10. Kruise - InplaceSet • InplaceSet: • Predictability is critical in

    web-scale cluster • We prefer In-Place-Upgrade, because with thousands of pods reshuffled across cluster: • Topology changes, image re-warm, unexpected overhead, resource allocation churn … • Generally, we ❤ StatefulSet, but: • SS will still tear down pods during rolling upgrade • Less rollout strategy than Deployment Deployment StatefulSet InplaceSet Ordering No Yes Yes Naming Random Ordered Ordered PVC reserve No Yes Yes Retry on other nodes No No Yes Rollout policy Rolling, Recreate Rolling, On- delete Rolling, On-delete, In-place Pause/Resume Yes No Yes Partition No Yes Yes Max unavailable Not yet Yes Yes Pre/Post update hook No No Yes InplaceSet = A in-place “StatefulSet” with more rollout strategies
  11. Kruise - BroadcastJob • BroadcastJob • A blend of DaemonSet

    and Job • Run pods on all machines exactly once • Use case: software upgrade, node validator, node labeler etc • and tons of other use cases in this issue #36601 https://github.com/kubernetes/kubernetes/issues/36601
  12. Scalability Matters • Scalability goal in our web-scale cluster •

    More than 10k nodes • More than 300k pods • Non-goal: • Total containers & pods per node • Scalability boundary of upstream K8s (v1.14) • No more than 5k nodes • No more than 150k total pods • No more than 300k total containers • No more than 100 pods per node • Question: • How to discover scalability issue in 10k nodes cluster?
  13. Performance Benchmark Toolkit • kubemark with HTTP interface • Hollow-Node

    Pods • cmd/kubemark/hollow-node.go • Taint and drain nodes for perf test, and run it • Typical test cases in 10k nodes cluster: • Start up time during scaling pods • Time of creating and deleting pods • Pod listing RT • Failure counts Perf master kubelet master curl -X POST -H "Content-Type: application/json" \ "https://k8s-performance-toolkit.alibaba-inc.com/api/kubemark/test" \ -d '{"test_focus":"\\[Feature:Performance\\]","test_skip":"handle","node_count":10000,"pods_per_node":30}' How to run?
  14. Discover Performance Bottlenecks Concurrency, locking, data store Large amount of

    lister & watcher Large amount of heartbeat data Our own implementation, no worries :-)
  15. Fix Performance Issue • etcd • Periodic commit operation does

    not block concurrent read transactions: etcd-io/etcd#9296 • Fully allow concurrent large read: etcd-io/etcd#9384 • Improve index compaction blocking by using a copy on write clone to avoid holding the lock for the traversal of the entire index: etcd-io/etcd#9511 • Improve lease expire/revoke operation performance: etcd-io/etcd#9418 • Use segregated hash map to boost the freelist allocate and release performance: etcd-io/bbolt#141 • Add backend batch limit/interval fields: etcd-io/etcd#10283 • Benchmark: • 100 clients, 1 million random key value pairs, 5000 QPS • Completion time: ~200s • Latency: 99.9% in 97.6ms
  16. Fix Performance Issue • kube-apiserver: indexing, caching & reduce data

    scale • Pod List Indexing: ~35x improvement (will be upstream soon) • Watch Bookmark: k8s.io/kubernetes#75474 (New!) • Cherry pick: k8s.io/kubernetes#14733 (incremental heartbeat), k8s.io/kubernetes#63606 • Benchmark: • 10k nodes, 100K exiting pods, scale 2000 pod • QPS: 133.3 pods/s, 99 %ile 3.474s • On going: metrics data will crash Prometheus
  17. Dance with Upstream • “non fork” • Keep upgrading with

    2 releases lag with upstream • No API change • annotations, aggregator, CRD etc • Respect K8s philosophy • Declarative API & Controller Pattern • Leverage K8s interfaces & extensibility • CNI, CSI, admission hook, initializer, extender etc • Honor kubelet & CRI • “fork” • Lock down on specific K8s release, never upgrade • In-house/modified K8s API, hide/wrap K8s API • Bypass K8s core workflow • Bypass K8s interface (CSI, CNI, CRI) • Replace kubelet with some other agent • … One more thing: set up a small upstream team across your org, it’s fun, and rewarding.