PVC問題 - おうちk8s構築
longhornを導入する
Daemonsetのlonghorn managerが起動しない問題
kubectl describe daemonset longhorn-manager -n longhorn-systemでEventを確認する。
エラーの主な内容としては以下
Error creating: pods "longhorn-manager-" is forbidden: no PriorityClass with name longhorn-critical was foundError creating: pods "longhorn-manager-vcz9b" is forbidden: violates PodSecurity "baseline:latest": hostPath volumes (volumes "boot", "dev", "proc", "etc", "longhorn"), privileged (container "longhorn-manager" must not set securityContext.privileged=true)まず、下部のPriorityClass関連エラーに関して。k8sのPriority classは何なのかというと、公式ではこれ(https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass)。設定されたpriority classごとにPodの優先度付をし、cluster resource逼迫時などにどのPodを優先させるかを決定するためのものらしい。
cluster-wideなリソースとして存在していて、globalDefaultなPriorityClassが存在せず、PriorityClassが明示的に割り当てられていないPodのpriorityは0として扱われる。数値が大きいほど優先される。
kubectl get priorityclassで確認することができる。以下結果。
kubectl get priorityclass -A
NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY
longhorn-critical 1000000000 false 42m PreemptLowerPriority
system-cluster-critical 2000000000 false 24d PreemptLowerPriority
system-node-critical 2000001000 false 24d PreemptLowerPriorityこれを見るに、longhorn-criticalというPriorityClassは存在しているので継続した問題とはなっていない模様。
下の方のPodSecurityに関するエラーは、k8s clusterをtalos linux上に構築しているために、talos linuxのdefaultのPodSecurity ruleに違反したという問題。
talos linuxにおける記述: https://www.talos.dev/v1.9/kubernetes-guides/configuration/pod-security/
k8s公式のPod Securityに関する記述: https://kubernetes.io/docs/concepts/security/pod-security-standards/
k8s公式のnamespaceに対するPod Security設定に関する記述: https://kubernetes.io/docs/tasks/configure-pod-container/enforce-standards-namespace-labels/
今回でいうと、longhorn-systemというnamespaceに対してPod Securityを緩和することでエラーが解消する見込み。これはvolumeをhost machine二マウントするために必要な緩和である。
これを対応すると、次はlonghorn-managerのDaemonSetの各Podの起動時にエラーが発生する
time="2025-02-22T17:26:47Z" level=fatal msg="Error starting manager: failed to check environment, please make sure you have iscsiadm/open-iscsi installed on the host: failed to execute: /usr/bin/nsenter [nsenter --mount=/host/proc/216642/ns/mnt --net=/host/proc/216642/ns/net iscsiadm --version], output , stderr nsenter: failed to execute iscsiadm: No such file or directory\n: exit status 127" func=main.main.DaemonCmd.func3 file="daemon.go:105"これは、k8s node hostであるtalos linuxに、CSI driverがinstallされていないことに起因すると思われる。talosctlの設定を変更することでこれに対応できる見込み。(執筆中)
talos linuxにextensionを追加する方法(https://www.talos.dev/v1.9/talos-guides/configuration/system-extensions/)
特にlonghornで使用するopen-iscsiに関する説明はこれ(https://www.talos.dev/v1.9/kubernetes-guides/configuration/storage/#others-iscsi)
talosctl upgrade --nodes 192.168.xxx.yyyy --nodes factory.talos.dev/installer/613e1592b2da41ae5e265e8789429f22e121aab91cb4deb6bc3c0b6262961245:v1.9.4でworker nodeのupgradeを行う。(一台ずつ)
system extensionを含むfactory imageはhttps://factory.talos.dev/ で作成した。
これによってlonghorn自体のエラーは解消された。
PVCを伴うbitnami/mysqlをclusterにデプロイするとPVがアタッチされmysqlが起動することを確認できる。
ref. https://light-of-moe.ddo.jp/~sakura/diary/?p=1575
ref. https://khenry.substack.com/p/longhorn-on-talos
ref. https://blog.uta8a.net/post/2024-11-20-learn-volume-of-k8s