我一直使用 来安装 kubernetes sudo apt install -y kubectl kubeadm kubelet
。现在出现以下消息
No apt package "kubeadm", but there is a snap with that name.
Try "snap install kubeadm"
No apt package "kubectl", but there is a snap with that name.
Try "snap install kubectl"
No apt package "kubelet", but there is a snap with that name.
Try "snap install kubelet"
现在如果我这样做
sudo snap install kubectl --classic
sudo snap install kubeadm --classic
sudo snap install kubelet --classic
我明白了
[init] Using Kubernetes version: v1.27.1
[preflight] Running pre-flight checks
W0517 14:44:01.250068 1034876 checks.go:1064] [preflight] WARNING: Couldn't create the interface used for talking to the container runtime: crictl is required by the container runtime: executable file not found in $PATH
[WARNING FileExisting-ethtool]: ethtool not found in system path
[WARNING FileExisting-socat]: socat not found in system path
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
如果我做systemctl enable kubelet.service
我得到:
Failed to enable unit: Unit file kubelet.service does not exist.
Canonical 做了什么?他们破坏了 kuberetes 的安装。
有人有可以与 Canonical 所做的任何操作配合使用的脚本吗?我在使用 Ubuntu 20.04。
答案1
从错误来看,你似乎缺少了 crictl,它是https://github.com/kubernetes-incubator/cri-tools/releases 您可以尝试类似这样的方法来安装它
go get github.com/kubernetes-incubator/cri-tools/cmd/crictl
答案2
这个人@ognjen011 最近留下了一条评论,更像是随意的问候,而不是建设性的回应。
抱歉绕了这么远,但我也遇到了类似的问题。
看起来,通过 snap 安装时,systemctl 配置被绕过,导致 kubetools 缺少“.service”,从而阻止其运行。
我在使用 Debian 10 时偶然发现了这个错误。
删除 Kubernetes 工具的 apt 安装选项似乎是不明智的。
答案3
命令“sudo snap install kubelet --classic”创建的单元文件是snap.kubelet.daemon.service,而不是kubelet.service
$ find /etc/systemd/ | grep kubelet
/etc/systemd/system/snapd.mounts.target.wants/snap-kubelet-3236.mount
/etc/systemd/system/multi-user.target.wants/snap.kubelet.daemon.service
/etc/systemd/system/multi-user.target.wants/snap-kubelet-3236.mount
/etc/systemd/system/snap.kubelet.daemon.service
/etc/systemd/system/snap-kubelet-3236.mount
所以这就是为什么“sudo systemctl enable kubelet.service”会生成“无法启用单元:单元文件 kubelet.service 不存在”错误消息。
运行以下命令,不再出现错误消息(很可能已通过“sudo snap install kubelet --classic”命令启用)
$ sudo systemctl enable snap.kubelet.daemon.service
Check status
$ sudo systemctl status snap.kubelet.daemon.service
or
$ sudo systemctl status snap.kubelet.daemon
● snap.kubelet.daemon.service - Service for snap application kubelet.daemon
Loaded: loaded (/etc/systemd/system/snap.kubelet.daemon.service; enabled; preset: enabled)
Active: active (running) since Sat 2024-04-20 00:18:32 PDT; 13min ago
Main PID: 11576 (kubelet)
Tasks: 14 (limit: 5815)
Memory: 30.2M
CPU: 23.940s
CGroup: /system.slice/snap.kubelet.daemon.service
└─11576 /snap/kubelet/3236/kubelet
环境:Ubuntu 23.10 桌面版、Ubuntu 23.10 服务器版