Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cluster AutoscalerをTerraformとHelmfileでデプロイしてPro...
Search
Hidetake Iwata
November 13, 2019
Technology
3
1.7k
Cluster AutoscalerをTerraformとHelmfileでデプロイしてPrometheusでモニタリングする / Deploy the Cluster Autoscaler with Terraform and Helmfile, Monitor with Prometheus
Kubernetes Meetup Tokyo #25
2019.11.13
Hidetake Iwata
November 13, 2019
Tweet
Share
More Decks by Hidetake Iwata
See All by Hidetake Iwata
Rewrite Go error handling using AST transformation
int128
1
1.3k
認証の仕組みとclient-go credential plugin / authentication and client-go credential plugin
int128
7
7.3k
CLIでOAuth/OIDCを快適に利用する
int128
0
800
AppEngine × Spring Boot × Kotlin
int128
0
94
いつものJIRA設定
int128
1
170
Swaggerのテンプレートを魔改造した話 / Customize Swagger Templates
int128
1
4.7k
本番環境のリリースを自動化した話
int128
0
720
Swagger × Spring Cloud
int128
0
86
The Evolution of System Architecture
int128
0
160
Other Decks in Technology
See All in Technology
[2025-02-07]生成AIで変える問い合わせの未来 〜チームグローバル化の香りを添えて〜
tosite
1
290
Developers Summit 2025 浅野卓也(13-B-7 LegalOn Technologies)
legalontechnologies
PRO
0
150
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
770
Datadogとともにオブザーバビリティを布教しよう
mego2221
0
130
事業継続を支える自動テストの考え方
tsuemura
0
300
滅・サービスクラス🔥 / Destruction Service Class
sinsoku
6
1.5k
SCSAから学ぶセキュリティ管理
masakamayama
0
140
君はPostScriptなウィンドウシステム 「NeWS」をご存知か?/sunnews
koyhoge
0
720
サーバーレスアーキテクチャと生成AIの融合 / Serverless Meets Generative AI
_kensh
12
3k
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
6
1.4k
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
5.1k
スタートアップ1人目QAエンジニアが QAチームを立ち上げ、“個”からチーム、 そして“組織”に成長するまで / How to set up QA team at reiwatravel
mii3king
1
1.1k
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Site-Speed That Sticks
csswizardry
3
370
The World Runs on Bad Software
bkeepers
PRO
67
11k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Automating Front-end Workflow
addyosmani
1367
200k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
How to train your dragon (web standard)
notwaldorf
90
5.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Designing for humans not robots
tammielis
250
25k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Producing Creativity
orderedlist
PRO
343
39k
Transcript
Cluster Autoscalerを TerraformとHelmfileでデプロイして Prometheusでモニタリングする Kubernetes Meetup Tokyo #25 Hidetake Iwata
at NTT DATA (@int128)
2 Who are you? Software Engineer at NTT DATA, working
on DevOps and Cloud Native Technology R&D. Author of kubectl plugins (kubelogin, kauthproxy).
お話しすること • Cluster Autoscalerのデプロイ(Terraform, Helmfile) • Cluster Autoscalerのモニタリング(Prometheus, Grafana) お話ししないこと
• Cluster Autoscalerのマニアックな仕様 今日お話しすること 3 CI/CD Observability
クラスタに必要なリソース(CPU Request, Memory Request)に応じて、 ノード数を自動的に増減させるツール。 Kubernetes Cluster Cluster Autoscalerとは Worker
Nodes https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler クラスタに必要なリソースを計算する (Core) 例:メモリ不足で新しい Podが起動できないため、ノードの追 加が必要と判断する クラウド依存のスケール処理を行う (Cloud Provider) 例:AWSの場合はAuto Scaling GroupのDesired Capacityを 増やす 4
公式のHelm Chartを利用するとCluster Autoscalerを簡単にデプロイできる。(GCP やAzureの場合はマネージドサービスで設定できる) Helm Chart Cluster Autoscalerのデプロイ https://github.com/helm/charts/tree/master/stable/cluster-autoscaler stable/cluster-autoscaler
5 Helm Release Deployment Cluster Role Service Account ...
AWS Cluster Autoscalerのデプロイ AWSの場合、Cluster AutoscalerにIAM Roleを割り当てて、Cluster Autoscalerが Auto Scaling Groupを操作できる必要がある。
6 stable/cluster-autoscaler Deployment stable/kube2iam DaemonSet Auto Scaling Group IAM Role (Cluster Autoscaler) Cluster AutoscalerがAWS APIに アクセスする kube2iamが一時的なクレデン シャルを取得する IAM Role (Worker) https://github.com/jtblin/kube2iam
クラスタにデプロイするHelm Releasesを宣言的に管理できるツール。 すべてデプロイするには: $ helmfile sync YAMLとクラスタの差分を表示するには: $ helmfile diff
Helmfileとは https://github.com/roboll/helmfile 7 # helmfile.yaml releases: - name: cluster-autoscaler namespace: kube-system chart: stable/cluster-autoscaler values: - cloudProvider: aws awsRegion: {{ env "AWS_REGION" }} - name: kube2iam namespace: kube-system • Helm ReleasesのセットをYAMLで宣言できる • 設定値はインラインでも外部ファイルでも OK • テンプレートで環境変数を参照できる
Helm ReleasesはHelmfile、AWSのリソースはTerraformでデプロイする。 (Terraformでも管理できるけどHelmfileの方がおすすめ※) HelmfileとTerraformによるデプロイ Auto Scaling Group IAM Role (Worker)
stable/cluster-autoscaler helmfile.yaml *.tf Helmfile Terraform ※個人の感想です 8 stable/kube2iam IAM Role (CA)
CI Ops AWS Cluster Autoscalerのデプロイメントパイプライン Helmfile Terraform 9 Git Repository
Auto Scaling Group IAM Role (Worker) stable/cluster-autoscaler stable/kube2iam IAM Role (CA) helmfile.yaml *.tf HelmfileでGitOpsも可能らしい (未検証)
Cluster Autoscalerの動作確認(1/2) CPU Requestの大きなPodをデプロイすると、ノードが追加される。 10 I0927 11:50:35.158353 1 scale_up.go:263] Pod
echoserver/echoserver-74fd7d865f-vkzqb is unschedulable I0927 11:50:35.158391 1 scale_up.go:300] Upcoming 0 nodes I0927 11:50:35.158521 1 scale_up.go:423] Best option to resize: ASG_NAME I0927 11:50:35.158540 1 scale_up.go:427] Estimated 1 nodes needed in ASG_NAME I0927 11:50:35.158556 1 scale_up.go:529] Final scale-up plan: [{ASG_NAME 4->5 (max: 8)}] I0927 11:50:35.158572 1 scale_up.go:694] Scale-up: setting group ASG_NAME size to 5 I0927 11:52:36.144782 1 clusterstate.go:194] Scale up in group ASG_NAME finished successfully in 2m0.794268739s
Cluster Autoscalerの動作確認(2/2) デフォルトでは、Cluster Autoscalerがノードが必要ないと判断してから10分後にノー ドが削除される。 11 I0927 11:57:07.790306 1 scale_down.go:407]
Node ip-172-19-67-52.ap-northeast-1.compute.internal - utilization 0.055000 I0927 11:57:07.790634 1 static_autoscaler.go:359] ip-172-19-67-52.ap-northeast-1.compute.internal is unneeded since 2019-09-27 11:57:07.773690521 +0000 UTC m=+2997.491422805 duration 0s I0927 12:07:12.161679 1 static_autoscaler.go:359] ip-172-19-67-52.ap-northeast-1.compute.internal is unneeded since 2019-09-27 11:57:07.773690521 +0000 UTC m=+2997.491422805 duration 10m4.367847963s I0927 12:07:12.391908 1 auto_scaling_groups.go:269] Terminating EC2 instance: i-066bc60549f083e38
Cluster Autoscalerのモニタリング Cluster Autoscalerは以下の方法でモニタリングできる。 • メトリクスをPrometheusで取得する。 ←本スライドで説明 • Podのログを参照する。 • ConfigMapに格納されているステータスを参照する。
• Eventをsubscribeする。 12 https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/proposals/metrics.md
Prometheus OperatorのServiceMonitorリソースを利用すると、 監視対象のServiceとPrometheusを紐づけることができる。 同じNamespaceに配置する必要がある Prometheus ServiceMonitorとは Prometheus ServiceMonitor Service Pod
(exporter) Grafana https://github.com/coreos/prometheus-operator/blob/master/Documentation/user-guides/running-exporters.md 13
# 実際に生成されるマニフェスト apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: labels: prometheus: kube-prometheus
release: prometheus-operator name: cluster-autoscaler-aws-cluster-autoscaler namespace: monitoring # helmfile.yaml releases: - name: cluster-autoscaler namespace: kube-system chart: stable/cluster-autoscaler values: - serviceMonitor: enabled: true namespace: monitoring selector: release: prometheus-operator Cluster AutoscalerのServiceMonitor Cluster AutoscalerのHelm ChartにはServiceMonitorが含まれている。 このラベルが付いた Prometheusに登録される 14
15 Cluster AutoscalerのGrafanaダッシュボード https://grafana.com/grafana/dashboards/3831
Cluster Autoscalerを TerraformとHelmfileでデプロイして Prometheusでモニタリングする シリーズにできるかも?? 16
まとめ Cluster Autoscalerを利用すると、クラスタに必要なリソースに応じてノード数を自動 的に増減できます。 TerraformとHelmfileによるCluster Autoscalerのデプロイ、 PrometheusとGrafanaによるCluster Autoscalerのモニタリング について説明しました。 17
※記載されている会社名、商品名、サービス名は各社の登録商標または商標です。