LoginSignup
4
1

More than 1 year has passed since last update.

Nodeのメンテナンスとkubectl drain コマンドについて

Posted at

Maintenance

クラスターの一部のノードで、ソフトウェアのアップグレードや、セキュリティパッチを適用させたい場合など、メンテナンスでノードを停止させたい場面が出てくる。

そこで、Node内のPodを、一時的に別のNodeに退避させたり、スケジューラの対象から外したりすることで、メンテナンスを行う。

kubectl cordonとdrain

スクリーンショット 2022-01-23 14.20.15.png

kubectl drain

該当のNodeで、Podをスケジュールさせることはできない。
Podを他のNodeに移動させたあと、その間にNodeを再起動させたり、メンテナンスをする。
ただ、調べた感じ、使用シーンとしては、他のNodeに退避させて、その間にメンテナンスと言うよりは、Graceful Shutdownを実現するために使われているような印象を受けました。

スクリーンショット 2022-01-23 14.25.17.png

参考
https://kubernetes.io/ja/docs/tasks/run-application/run-replicated-stateful-application/#%E3%83%8E%E3%83%BC%E3%83%89%E3%82%92drain%E3%81%99%E3%82%8B
https://kubernetes.io/ja/docs/concepts/scheduling-eviction/_print/#node%E3%81%AE%E9%9A%94%E9%9B%A2%E3%82%84%E5%88%B6%E9%99%90

kubectl cordon

既存のノード上のPodは終了したり、移動しない。余分なポッドがノードに追加されるのを防ぐ。
ノードが cordon された後は、新しいポッドをそのノードにスケジュールすることはできない。
該当のNodeで、新しいPodはスケジュールされず、既存のPodは動き続ける。

スクリーンショット 2022-01-23 14.54.56.png

kubectl drainの挙動

ノード上で実行している全てのPodを退避させる排出処理(drain)を行うには、kubectl drainを使う。

ノードが排出処理を開始すると、ノードをSchedulingDiasabledに変更してから、各Podに対してSIGTERMシグナルを送信し、Podを退避させる。

排出処理を開始すると、停止可能なPodは退避処理(Eviction)が行われる。

また、排出処理にはそれ以降のスケジューリング候補から除外する機能も含まれているため、前もってkubectl cordonで、指定したNodeにスケジュールさせないよう、実行する必要もない。

例えばこんな感じ。

まず、ポッドを確認。

root@controlplane:~# kubectl get pods -o wide
NAME   READY   STATUS    RESTARTS   AGE     IP  NODE     NOMINATED NODE   READINESS GATES
aws1   1/1     Running   0          3m24s   xx  node01   <none>           <none>
aws2   1/1     Running   0          3m24s   xx  node01   <none>           <none>
aws3   1/1     Running   0          3m24s   xx  node01   <none>           <none>

drain実行。

root@controlplane:~# kubectl drain node01 --ignore-daemonsets 
node/node01 cordoned
WARNING: ignoring DaemonSet-managed Pods: 
kube-system/kube-flannel-ds-hoge, kube-system/kube-proxy-fuga
evicting pod default/aws1
evicting pod default/aws2
evicting pod default/aws3
pod/aws1 evicted
pod/aws2 evicted
pod/aws3 evicted
node/node01 evicted

PodがEvictedされている。

参考

https://networkandcode.wordpress.com/2019/10/10/kubernetes-nodes-drain-or-cordon-nodes/
https://intl.cloud.tencent.com/document/product/457/30654
https://cloud.google.com/kubernetes-engine/docs/tutorials/migrating-node-pool
https://qiita.com/toshihirock/items/d22fee20b1a561b9efea
https://qiita.com/tkusumi/items/946b0f31931d21a78058
https://www.mtioutput.com/entry/2020/06/21/000000
https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/

参考にさせていただきました。ありがとうございます。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1