我遵循 kubernetes-the-hard-way 创建 k8s 集群,因为我没有 ARM 设备,所以我使用 4 个 x86 架构的虚拟机。这是与指南唯一不同的地方。
所有步骤都很顺利,直到第 09 章-bootstrapping-kubernetes-workers,节点尚未准备好:
"kubectl get nodes \
--kubeconfig admin.kubeconfig"
NAME STATUS ROLES AGE VERSION
node-0 NotReady <none> 94s v1.31.2
node-1 NotReady <none> 98s v1.31.2
通过describe节点进一步检查,根本原因是KubeletHasSufficientMemory
实际上,节点要有足够的内存,并且swap是关闭的。
root@node-0:~# free -m
total used free shared buff/cache available
Mem: 1967 869 356 26 920 1097
Swap: 0 0 0
root@server:~# kubectl describe nodes --kubeconfig admin.kubeconfig
Name: node-0
Roles: <none>
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
kubernetes.io/hostname=node-0
kubernetes.io/os=linux
Annotations: node.alpha.kubernetes.io/ttl: 0
volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp: Sun, 15 Dec 2024 04:56:26 -0600
Taints: node.kubernetes.io/not-ready:NoSchedule
Unschedulable: false
Lease:
HolderIdentity: node-0
AcquireTime: <unset>
RenewTime: Sun, 15 Dec 2024 05:12:08 -0600
Conditions:
Type Status LastHeartbeatTime LastTransitionTime Reason Message
---- ------ ----------------- ------------------ ------ -------
MemoryPressure False Sun, 15 Dec 2024 05:11:55 -0600 Sun, 15 Dec 2024 04:56:26 -0600 KubeletHasSufficientMemory kubelet has
sufficient memory available
DiskPressure False Sun, 15 Dec 2024 05:11:55 -0600 Sun, 15 Dec 2024 04:56:26 -0600 KubeletHasNoDiskPressure kubelet has
no disk pressure
PIDPressure False Sun, 15 Dec 2024 05:11:55 -0600 Sun, 15 Dec 2024 04:56:26 -0600 KubeletHasSufficientPID kubelet has
sufficient PID available
Ready False Sun, 15 Dec 2024 05:11:55 -0600 Sun, 15 Dec 2024 04:56:26 -0600 KubeletNotReady container r
untime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initiali
zed
Addresses:
InternalIP: 192.168.122.26
Hostname: node-0
Capacity:
cpu: 1
ephemeral-storage: 19480400Ki
我找到原因了,不是内存资源问题。 实际错误是
Network plugin returns error: cni plugin not initialized
Ready False Sun, 15 Dec 2024 05:11:55 -0600 Sun, 15 Dec 2024 04:56:26 -0600 KubeletNotReady container r
untime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initiali
原来是我忘记了步骤:
创建桥接网络配置文件:
mv 10-bridge.conf 99-loopback.conf /etc/cni/net.d/
重复此步骤后,重新启动
containerd kubelet kube-proxy
节点状态为Ready。