More Related Content Similar to Kubernetes ControllerをScale-Outさせる方法 / Kubernetes Meetup Tokyo #55 (20) More from Preferred Networks (20) Kubernetes ControllerをScale-Outさせる方法 / Kubernetes Meetup Tokyo #552. 2
@everpeace
▶ Preferred Networks, Inc. / エンジニア
▶ 社内向けオンプレML基盤の開発運用
▶ 社内クラスタ向けにkube-schedulerを拡張
▶ kubernetes sig-scheduling/sig-node でも
時々活動中
Shingo OMURA / @everpeace
4. 4
@everpeace
● おさらい: Kubernetes Controllerのアーキテクチャ
● Kubernets ControllerをScale-Outする方法
○ Namespace単位のSharding
○ Resource単位のSharding
● Kubernetes自体のScalability限界に注意
● ControllerをShardingさせて嬉しい時
● まとめ
本日の流れ
6. 6
@everpeace
Kubernetes Controller とは
Icons made by Gregor Cresnar, Kiranshastry, Icon Pond, Icon Monk from www.flaticon.com is licensed by CC 3.0 BY
kind: MyKind
metadata:
name: my-name
Watching
(Custom) Resources
& Cluster State
Reconciling
Cluster State
Controller
Custom Resourceを使って
Kubernetesを拡張するパターンは
オペレータパターンとも呼ばれます
15. 15
@everpeace
Shardingパターンを考える
Sharding単位 難易 概要 Pros Cons
Namespace
単位
易 ControllerをNamespace
単位にデプロイ
● 特定のnamespaceだけを
対象とするcontrollerは
すぐ作れる
● Manifestもそのまま使え
そう
● SAの権限がNamespaceに
閉じる
● Controller Podが大量に必要
(Podも一応resource)
● Namespace増減の対応難しい
● Cross-Namespace処理NG
● Cluster ScopeなResourceは
対応不可
● Namespace間での負荷は偏る
Resource
単位
難 Consistent Hashing等を
つかって各Podが担当す
るresourceを分散させる
● 1 Deploymentでいい
● Podの増減にしたがって
shardingも追従できるの
でscale outできる
● Frameworkのサポートが
まだ無い
16. 16
@everpeace
● 方法
○ 各namespaceのControllerをデプロイ
○ Reconcileは該当Namespaceのみ対象
(controller-runtimeだとmanager optionで
指定するだけ)
Namespace単位のSharding
Leader
Follower
Follower
ns-1
Leader
Follower
Follower
ns-2
Leader
Follower
Follower
ns-3
Argo Workflow Controller
とかは対応している
担当Namespace
のResourceだけ
をReconcile
17. 17
@everpeace
● Pros
○ 実装が簡単
○ Manifestもほぼそのまま使える
○ SAの権限がNamespaceに閉じる
(Namespace間のIsolationが大事な時は
これが良い)
● Cons
○ Controller Podが大量に必要
○ Namespaceの増減に対応しずらい
○ Namespace間での負荷は偏る
○ Cross-Namespaceな処理NG
○ Cluster ScopeなResource不可
Namespace単位のSharding
Leader
Follower
Follower
ns-1
Leader
Follower
Follower
ns-2
Leader
Follower
Follower
ns-3
Argo Workflow Controller
とかは対応している
担当Namespace
のResourceだけ
をReconcile
18. 18
@everpeace
Resource単位のSharding
● Towards Horizontally Scalable Kubernetes Controllers
○ Tim Ebert (@timebertt) 氏の修士論文
(バーデンヴュルテンベルク州協同州立大学)
● Github Repos
○ timebertt/thesis-controller-sharding
■ 修士論文本体
○ timebertt/kubernetes-controller-sharding
■ Shardingに対応したサンプルController実装
○ timebertt/controller-runtime@v0.12.3-sharding-1
■ Sharding対応のcontroller-runtime
Tim Ebert
@timebertt
Cloud Engineer
@stackitcloud
working on
#Kubernetes
@GardenerProject
19. 19
@everpeace
Resource単位のSharding
出典: "Towards Horizontally Scalable Kubernetes Controllers," Tim Ebert
● ShardはLeaseで定義
○ Shard名 = Lease名 = Pod名
(StatefulSetだとShard名を安定させられる)
● Sharder (Singleton)
○ Shard群をwatchして、
○ Resource群をshardに割り振り
リソースに shard:<shard名>を付与
(by Consistent Hashing)
● Controller (≒Shard)
○ 自身のShard(Lease)を管理
○ shard:<shard名>ラベルが付いている
リソースのみをReconcile
21. 21
@everpeace
Shardメンバーシップと耐障害性
Sharder Controller Sharder Controller Sharder Controller
<Leader>
Lease
(Shard)
Lease
(Shard)
Lease
(Shard)
SharderがSingleton
Shardメンバシップの認識を一箇所で集中
管理にすることで認識ズレが起きない
(ズレが起きるとObjectのShard割当が
乱れて並行更新が起きる)
ShardがLease (Podじゃない)
Shard=PodだとRollingUpdate等で短期間Pod
が不在なだけでShardが不在になってObject
の再割り当てが必要に。Leaseだと短期間の
Pod不在に対してRobustになる。
Health icons created by Freepik - Flaticon
23. 23
@everpeace
Objectの振り分け = Consistent Hashing
Lease
(Shard)
Lease
(Shard)
Lease
(Shard)
Sharder
Lease
(Shard)
obj1
obj2
obj3
obj4
obj4
obj5
obj6
obj7
<Leader>
Lease
(Shard)
Lease
(Shard)
Lease
(Shard)
Sharder
Lease
(Shard)
obj1
obj2
obj3
obj4
obj4
obj5
obj6
obj7
<Leader>
Consistent Hashing
Shardの追加削除に対して
Shard間のオブジェクトの移動が
少なくできる
25. 25
@everpeace
オブジェクトの割当
kind: MyKind
metadata:
name: obj1
labels:
shard: shard-a
kind: MyKind
metadata:
name: obj2
labels:
shard: shard-a
Sharder
Controller
(shard-a)
Watch&Reconcile
Label
Lease
(shard-a)
Sharder
obj1
<Leader>
obj2
SharderがLabelでShardを割当
shard labelの値はたかだか1つ重複割当が起きない
!!!ただしshard間の移動には注意!!!
旧shardと新shardが同時に
reconcileするのを防ぐ必要があります
(Sharderは旧shardでのreconcileが
停止されたことを知る必要がある)
27. 27
@everpeace
controller-runtime(Forked)でのsharding対応
mgr, err := manager.New(restConfig, manager.Options{
Sharded: true, // enable sharding for this manager
ShardID: "", // ShardID (default to Pod name)
ShardMode: sharding.ModeBoth, // Run Shard and Sharder(default)
})
① ManagerはOptionを指定
controller, err := builder.ControllerManagedBy(mgr).
For(&webhostingv1alpha1.Website{}, builder.Sharded{}).
Owns(&appsv1.Deployment{}, builder.Sharded{}).
Watches(...).
Build(reconciler)
② Reconcilerは普通に書いてbuilderでSharded optionを指定
これだけで
自Shard用のCache
Sharderが起動します
これだけで自Shard用の
Controller起動します
(Shard移動処理は自動)
32. 32
@everpeace
Kubernetes自体のScalability限界に注意
● Considerations for large clusters | Kubernetes に上限値の明記あり
○ No more than 110 pods per node
○ No more than 5000 nodes
○ No more than 150000 total pods
○ No more than 300000 total containers
● etcd 自体がすべての書き込みは直列処理する
➔ つまり更新はScale-Outしない
(--etcd-servers-overridesでgroup/resource単位でetcd更新負荷をOffload/分離可)
➔ せっかくController Scale-Outしても意味ない!?😇
eventだけ別etcd
とか見かけますよね