Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Autoscaling in Kubernetes
Search
Atsushi Tanaka
September 09, 2018
Programming
1.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Autoscaling in Kubernetes
Atsushi Tanaka
September 09, 2018
More Decks by Atsushi Tanaka
See All by Atsushi Tanaka
プロダクト専任SREを置かずに 信頼性を追求する
bgpat
1
140
OpenCensusと歩んだ7年間
bgpat
0
770
SREだけど社内営業組織の業務改善をしてみた
bgpat
0
990
ウォンテッドリーにおける Platform Engineering
bgpat
0
900
Wantedly での Datadog 活用事例
bgpat
2
6.5k
KubernetesでDatadogを飼うならオートディスカバリーを使わないと損
bgpat
2
1.1k
マイクロサービス基盤にフルマネージドサービスではなくKubernetesを選択する理由
bgpat
12
4.7k
400万ユーザーに価値を届けるエンジニアを を支えるインフラ基盤
bgpat
3
580
Ruby製社内ツールのGo移行
bgpat
2
900
Other Decks in Programming
See All in Programming
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
220
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.3k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
150
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
190
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
430
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
Java 27新機能 / Java 27 new features
kishida
2
190
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
720
How to Talk to Developers About Accessibility
jct
2
560
The Mindset for Success: Future Career Progression
greggifford
PRO
0
520
Paper Plane
katiecoart
PRO
4
53k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
540
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
Skip the Path - Find Your Career Trail
mkilby
1
240
GraphQLとの向き合い方2022年版
quramy
50
15k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
550
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Transcript
©2018 Wantedly, Inc. Autoscaling in Kubernetes KubernetesͱΦʔτεέʔϧ ,VCFSOFUFT LT ษڧձ!ຊϚΠΫϩιϑτגࣜձࣾ
9.Sep.2018 - Atsushi Tanaka - @bgpat
©2018 Wantedly, Inc. • Atsushi Tanaka ాதಞࢤ • Infrastructure
Engineer at Wantedly, Inc. • Interested in k8s, Docker and Golang About @bgpat
©2018 Wantedly, Inc. Φʔτεέʔϧͷ
©2018 Wantedly, Inc. https://ja.wikipedia.org/wiki/εέʔϥϏϦςΟ "εέʔϧ"
©2018 Wantedly, Inc. https://ja.wikipedia.org/wiki/εέʔϥϏϦςΟ "εέʔϧ"
©2018 Wantedly, Inc. ෛՙʹ߹ΘͤͯࣗಈͰαʔόʔΛ֦ு͢Δ
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS w $MVTUFS"VUPTDBMFS w 7FSUJDBM1PE"VUPTDBMFS w
"EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS w $MVTUFS"VUPTDBMFS w 7FSUJDBM1PE"VUPTDBMFS w
"EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ ਫฏεέʔϧ ਨεέʔϧ
©2018 Wantedly, Inc. εϖοΫ Scale Out Scale In Scale
Down Scale Up
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS w $MVTUFS"VUPTDBMFS w 7FSUJDBM1PE"VUPTDBMFS w
"EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ /PEF 1PE
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS )1" w $MVTUFS"VUPTDBMFS w
7FSUJDBM1PE"VUPTDBMFS w "EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ
©2018 Wantedly, Inc. w ϝτϦΫε͕ઃఆΛ͍͑ͯͳ͍͔ࢹ w 1PEͷΛ૿͢ݮΒ͢ EFQMPZNFOUͷSFQMJDBTͷΛมߋ ࣮ࡍʹεέʔϧΛߦ͏ͷεέδϡʔϥʔ Horizontal
Pod Autoscaler
©2018 Wantedly, Inc. /PEF /PEF /PEF Kubernetesͷεέʔϧ 1PE 4FSWJDF 1PE
1PE 1PE 1PE %FQMPZNFOU 3FQMJDB4FU Service Pod ʹରͯ͠ ϦΫΤετΛϩʔυόϥϯε͢Δ Deployment Pod ͷΛ Ұఆʹอͭ
©2018 Wantedly, Inc. εέʔϧ͢Δج४ w $16༻ͷΈ BVUPTDBMJOHW w Ϧιʔεʹඥ͘ϝτϦΫε
BVUPTDBMJOHW w Ϧιʔεʹඥ͔ͳ͍ϝτϦΫε LTW Horizontal Pod Autoscaler
©2018 Wantedly, Inc. HPA autoscaling/v1
©2018 Wantedly, Inc. HPA autoscaling/v1
©2018 Wantedly, Inc. HPA autoscaling/v1
©2018 Wantedly, Inc. HPA autoscaling/v1
©2018 Wantedly, Inc. autoscaling/v2 ෳͷϝτϦΫεΛઃఆՄೳ ͲΕ͔ͻͱͭͰᮢΛ͑Δͱεέʔϧ͢Δ • Resource: CPUɾϝϞϦ ͷ༻
• Object: Kubernetes ͕ཧ͢ΔϦιʔεͷϝτϦΫε • Pods: Pod ʹؔ͢ΔϝτϦΫε • External: Kubernetes ͷϦιʔεʹؔ࿈͠ͳ͍ϝτϦΫε Horizontal Pod Autoscaler
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. HPA autoscaling/v2
©2018 Wantedly, Inc. API ΛͬͯϝτϦΫεΛऔಘ͢Δ • Resource Metrics API •
Custom Metrics API • External Metrics API Horizontal Pod Autoscaler
©2018 Wantedly, Inc. • Metrics Server or Heapster • Pod
Λ Node ʹஔ͢Δͱ͖ʹΘΕΔ • औΕΔϝτϦΫε CPU ͱ ϝϞϦ ͷΈ Resource Metrics API
©2018 Wantedly, Inc. • CPU, ϝϞϦ༻ྔҎ֎ͷϝτϦΫε͕औΕΔ • API αʔόʔΛ༻ҙͯ͠Ϋϥελʹొ͠ͳ͍ͱ͍͚ͳ͍ •
Prometheus • Azure • Stackdriver Custom & External Metrics API
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS )1" w $MVTUFS"VUPTDBMFS w
7FSUJDBM1PE"VUPTDBMFS w "EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ
©2018 Wantedly, Inc. Pod Λεέδϡʔϧ͢ΔͨΊͷϊʔυ͕Γͳ͘ͳΔͱ ΫϥελΛߏ͢ΔϊʔυͷΛ૿͢ ରԠ͍ͯ͠Δ CloudProvider • AWS
• Azure • GCP Cluster Autoscaler
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS )1" w $MVTUFS"VUPTDBMFS w
7FSUJDBM1PE"VUPTDBMFS w "EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ
©2018 Wantedly, Inc. • Pod ͷਨεέʔϧ • resource.limit ͱ resource.request
Λมߋ • Node ͷεέδϡʔϦϯά࣌ʹӨڹ • ᮢࣗಈઃఆ • HPAͱͷซ༻Մೳ Vertical Pod Autoscaler
©2018 Wantedly, Inc. w )PSJ[POUBM1PE"VUPTDBMFS )1" w $MVTUFS"VUPTDBMFS w
7FSUJDBM1PE"VUPTDBMFS w "EEPO3FTJ[FS KubernetesͰ͑ΔΦʔτεέʔϧ
©2018 Wantedly, Inc. • Pod ͷதʹϦιʔεΛࢹ͢ΔίϯςφΛཱͯͯ (sidecar) ༻ྔʹ߹Θͤͯཁٻ͢ΔϦιʔεΛ૿ݮͤ͞Δ • ૿ݮ͢Δྔϊʔυͷʹґଘ
• ΫϥελΛߏ͢Δίϯϙʔωϯτʹ༻͍ΒΕ͍ͯΔ • cluster-autoscaler • metrics-server Addon Resizer
©2018 Wantedly, Inc. ͔͜͜Βࣄྫհ
©2018 Wantedly, Inc. • kops Ͱ AWS ্ʹߏங • ϊʔυ:
40 • αʔϏε: 70ݸ • ΞϓϦέʔγϣϯͷ࣮ • Ruby on Rails • Goݴޠ • Python (ػցֶश) • C++, Rust (ը૾ॲཧ) WantedlyͷKubernetesΫϥελ
©2018 Wantedly, Inc. • HPA + Custom Metrics • Prometheus
• k8s-prometheus-adapter • Prometheus Operator • nginx-exporter • Cluster Autoscaler WantedlyͰ͍ͬͯΔΦʔτεέʔϧ
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU manage manage metrics
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU metrics manage manage
©2018 Wantedly, Inc. Prometheus Operator https://coreos.com/operators/prometheus/docs/latest/user-guides/getting-started.html
©2018 Wantedly, Inc. Prometheus Operator apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata:
name: service-monitor namespace: custom-metrics labels: service-monitor: prometheus spec: selector: matchLabels: custom-metrics: prometheus namespaceSelector: any: true endpoints: - port: http - port: https custom-metrics: prometheus ͷϥϕϧ͕͍͍ͯΔαʔϏε Λࢹ
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU metrics manage manage
©2018 Wantedly, Inc. Nginxͷstub_status location /basic_status { stub_status; } Active
connections: 291 server accepts handled requests 16630948 16630948 31070465 Reading: 6 Writing: 179 Waiting: 106 ͪίωΫγϣϯΛ͏
©2018 Wantedly, Inc. Active connections: 291 server accepts handled requests
16630948 16630948 31070465 Reading: 6 Writing: 179 Waiting: 106 nginx-exporter # HELP nginx_connections_current Number of connections currently processed by nginx # TYPE nginx_connections_current gauge nginx_connections_current{state="active"} 2 nginx_connections_current{state="reading"} 0 nginx_connections_current{state="waiting"} 1 nginx_connections_current{state="writing"} 1
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU metrics manage manage
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU create create metrics
©2018 Wantedly, Inc. 1SPNFUIFVT 1SPNFUIFVT 1PE 1PE HPA + Custom
Metrics ͷߏ .BTUFS/PEF $VTUPN.FUSJDT "1*4FSWFS ,VCFSOFUFT "1*4FSWFS 1PE "QQMJDBUJPO /HJOY OHJOY FYQPSUFS proxy )1" metrics proxy stub_status 1SPNFUIFVT 1SPNFUIFVT 0QFSBUPS manage metrics %FQMPZNFOU scale 3FQMJDB4FU metrics manage manage
©2018 Wantedly, Inc. HPA apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: name:
wantedly spec: maxReplicas: 50 minReplicas: 20 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: wantedly metrics: - type: Resource resource: name: cpu targetAverageUtilization: 50 - type: Pods pods: metricName: nginx_connections_current{state="writing"} targetAverageValue: 2.5 CPU ͱ Nginx ͷ ͪίωΫγϣϯͰεέʔϧ
©2018 Wantedly, Inc. ΦʔτεέʔϧͱϦΫΤετ
©2018 Wantedly, Inc. ΦʔτεέʔϧͱϦΫΤετ
©2018 Wantedly, Inc. • αʔόʔͷίετ͕͑ΒΕͨ • EC2 30 → Pod
20 (EC2 7) • εύΠΫʹڧ͘ͳͬͨ(ؾ͕͢Δ) • Ξϥʔτ͕ݮͬͨ • ᮢܾΊ͕େม • ௨ৗ࣌ʹΪϦΪϦεέʔϧ͠ͳ͍Λ୳͢ KubernetesͷΦʔτεέʔϧΛಋೖͯ͠
©2018 Wantedly, Inc. • KubernetesͰ͑ΔΦʔτεέʔϧͷ • εέʔϧͷΈ • ઃఆͷํ •
࣮ࡍʹͬͯΈͨ • ߏྫ • Ͳ͏ͳ͔ͬͨ ·ͱΊ
©2018 Wantedly, Inc. • Custom Metrics Λಋೖ͢Δ • CPU͚ͩͷͱ͖ΑΓޮΑ͘Φʔτεέʔϧ͕͑Δ •
ΞϓϦέʔγϣϯͷىಈΛૣ͘͢Δ • ͘͢εέʔϧͯ͠ىಈ͕͍ͱεύΠΫʹউͯͳ͍ • API Server ͷΦϓγϣϯΛมߋ͢Δ • --horizontal-pod-autoscaler-sync-period • ϞχλϦϯάͰ͖ΔΈ • Wantedly Ͱ DataDog Λ͍ͬͯΔ KubernetesͷΦʔτεέʔϧಋೖͷTips