CentOS Stream 9
Sponsored Link

Kubernetes : ノードを削除する2023/10/20

 

既存の Kubernetes クラスターからノードを削除する場合は以下のように設定します。

[1] Manager ノードで、例として、[node03.srv.world] ノードを削除します。
[root@mgr ~]#
kubectl get nodes

NAME               STATUS   ROLES           AGE   VERSION
dlp-1.srv.world    Ready    control-plane   17h   v1.28.2
dlp.srv.world      Ready    control-plane   21h   v1.28.2
node01.srv.world   Ready    <none>          20h   v1.28.2
node02.srv.world   Ready    <none>          20h   v1.28.2
node03.srv.world   Ready    <none>          17h   v1.28.2

# 対象ノードを安全に削除するための事前準備
# --ignore-daemonsets ⇒ DeamonSet の Pod は無視
# --delete-emptydir-data ⇒ emptyDir ボリュームを持つ Pod は無視
# --force ⇒ 単体で作成された Pod も削除

[root@mgr ~]#
kubectl drain node03.srv.world --ignore-daemonsets --delete-emptydir-data --force

node/node03.srv.world cordoned
Warning: ignoring DaemonSet-managed Pods: kube-system/calico-node-fqf2f, kube-system/kube-proxy-rlcbx
node/node03.srv.world drained

# 一定時間経過後に確認
# 時間は環境によって異なる

[root@mgr ~]#
kubectl get nodes node03.srv.world

NAME               STATUS                     ROLES    AGE   VERSION
node03.srv.world   Ready,SchedulingDisabled   <none>   17h   v1.28.2

# 削除処理を実行

[root@mgr ~]#
kubectl delete node node03.srv.world

node "node03.srv.world" deleted

[root@mgr ~]#
kubectl get nodes

NAME               STATUS   ROLES           AGE   VERSION
dlp-1.srv.world    Ready    control-plane   17h   v1.28.2
dlp.srv.world      Ready    control-plane   21h   v1.28.2
node01.srv.world   Ready    <none>          20h   v1.28.2
node02.srv.world   Ready    <none>          20h   v1.28.2
[2] 削除したノードで、kubeadm の設定をリセットしておきます。
[root@node03 ~]#
kubeadm reset

W1020 09:46:46.476248   14397 preflight.go:56] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W1020 09:46:47.739659   14397 removeetcdmember.go:106] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] Deleted contents of the etcd data directory: /var/lib/etcd
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of directories: [/etc/kubernetes/manifests /var/lib/kubelet /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.
関連コンテンツ