EKSのManagedNodeGroup(以下MNG)のkubeletのパラメータ変更方法がわかりづらかったので記事にします。
パラメータ変更方法
MNGで使用するLaunchTemplateのusedataに以下の記述をします。
以下の例は未使用イメージをガベージコレクトするしきい値を変更するものです。
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
set -ex
# Inject imageGCHighThresholdPercent value unless it has already been set.
if ! grep -q imageGCHighThresholdPercent /etc/kubernetes/kubelet/kubelet-config.json;
then
sed -i '/"apiVersion*/a \ \ "imageGCHighThresholdPercent": 70,' /etc/kubernetes/kubelet/kubelet-config.json
fi
# Inject imageGCLowThresholdPercent value unless it has already been set.
if ! grep -q imageGCLowThresholdPercent /etc/kubernetes/kubelet/kubelet-config.json;
then
sed -i '/"imageGCHigh*/a \ \ "imageGCLowThresholdPercent": 50,' /etc/kubernetes/kubelet/kubelet-config.json
fi
--==MYBOUNDARY==--\
LaunchTemplateの変更を行った場合、MNGで管理しているNodeの入れ替えが発生するので注意してください。
Nodeの入れ替え後、以下のコマンドを実行することで設定が反映されているか確認することができます。
$ kubectl proxy
# 新しく作成されたNodeの名前を入れる
$ node_name=
# 適用されているkubeletの設定が表示される
$ curl -sSL "http://localhost:8001/api/v1/nodes/${node_name}/proxy/configz" | python3 -m json.tool
参考資料
以下の記事とやり方はほぼ同じなのですがMNGでは bootstrap.sh
は自動で実行されるので不要でした。
MNGでのuserdataの記述方法で bootstrap.sh
を呼び出す方法も記載されていますが
わざわざ bootstrap.sh
を実行せずとも、kubelet-config.json
を編集するだけでよさそうでした。