k3s 无法作为守护进程启动,但从命令行手动运行时可以运行

k3s 无法作为守护进程启动,但从命令行手动运行时可以运行

我正在尝试在 Redhat 操作系统上的 EC2 实例 (t3.xlarge) 上安装 k3s

操作系统版本:

$ cat /etc/*release
NAME="Red Hat Enterprise Linux"
VERSION="8.6 (Ootpa)"

我在服务器上安装了 mysql。这些是安装命令:

export K3S_DATASTORE_ENDPOINT='mysql://user:password@tcp(localhost:3306)/db_name'
curl -sfL https://get.k3s.io | sh -s - server --node-taint CriticalAddonsOnly=true:NoExecute --tls-san locahost

但是我收到了错误:

$ systemctl status k3s.service
● k3s.service - Lightweight Kubernetes
   Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Sun 2022-09-11 15:03:05 UTC; 5s ago
     Docs: https://k3s.io
  Process: 71759 ExecStartPre=/bin/sh -xc ! /usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service (code=exited, status=1/FAILURE)

Sep 11 15:03:05 ip-172-31-28-136.eu-central-1.compute.internal systemd[1]: k3s.service: Failed with result 'exit-code'.
Sep 11 15:03:05 ip-172-31-28-136.eu-central-1.compute.internal systemd[1]: Failed to start Lightweight Kubernetes.
Sep 11 15:03:10 ip-172-31-28-136.eu-central-1.compute.internal systemd[1]: k3s.service: Service RestartSec=5s expired, scheduling restart.
Sep 11 15:03:10 ip-172-31-28-136.eu-central-1.compute.internal systemd[1]: k3s.service: Scheduled restart job, restart counter is at 109.
Sep 11 15:03:10 ip-172-31-28-136.eu-central-1.compute.internal systemd[1]: Stopped Lightweight Kubernetes.

不过我设法使用以下方法手动运行:

k3s server

其结果:

$ k3s kubectl get nodes
NAME                                             STATUS   ROLES                  AGE   VERSION
ip-172-31-28-136.eu-central-1.compute.internal   Ready    control-plane,master   14m   v1.24.4+k3s1

问题是什么?

答案1

我知道您发布这篇文章已经有一段时间了,但我遇到了同样的问题,最终归结为 systemd 启动脚本中的语法错误。如果您查看 /etc/systemd/system/k3s.service,您会看到以下行:

ExecStartPre=/bin/sh -xc'!/usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service'

问题出在“/bin/sh -xc '!”部分。如果你用下面这一行替换那一行:

ExecStartPre=/usr/bin/systemctl 已启用 --quiet nm-cloud-setup.service

一切都将按照预期进行。

相关内容