Debian服务enable配置开启启动时,必须要有WantedBy的配置,他声明了服务运行在哪个级别下。 如果没有配置install部分的WantedBy,则会报错异常如下:

# systemctl enable kubelet
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

需要在servcie文件中添加WangtedBy配置如下:

[Install]
WantedBy=multi-user.target

最终的配置文件:

zhaowenyu@hzabj-ysf-nsf15:~$ cat /etc/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/srv/nbs/1/var/lib/kubelet
#--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest
ExecStart=/usr/bin/kubelet \
  --address=10.122.91.48 \
  --hostname-override=10.122.91.48 \
  --pod-infra-container-image=harbor-inner.qynsf.netease.com/library/pause-amd64:3.0 \
  --bootstrap-kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
  --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
  --root-dir=/srv/nbs/1/var/lib/kubelet \
  --cert-dir=/etc/kubernetes/pki \
  --client-ca-file=/etc/kubernetes/pki/ca.pem \
  --cluster-dns=10.178.4.2 \
  --cluster-domain=cluster.local \
  --network-plugin=cni \
  --cni-conf-dir=/etc/cni/net.d \
  --cni-bin-dir=/opt/cni/bin \
  --allow-privileged=true \
  --fail-swap-on=false \
  --anonymous-auth=false \
  --logtostderr=false \
  --log-dir=/var/log/kubelet \
  --cgroups-per-qos=true \
  --kube-reserved=cpu=400m,memory=600Mi,ephemeral-storage=2Gi \
  --system-reserved=cpu=100m,memory=300Mi,ephemeral-storage=2Gi \
  --eviction-hard=memory.available<400Mi,nodefs.available<10%,nodefs.inodesFree<5% \
  --enforce-node-allocatable=pods \
  --max-pods=110 \
  --rotate-certificates=true
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-06-19 08:59:50

results matching ""

    No results matching ""