Skip to content

systemctl running debug

zhangguanzhang edited this page Aug 14, 2020 · 8 revisions

例如kubelet

systemctl cat kubelet,然后把ExecStart的部分复制到终端,不要看下面我的是啥你就复制我的,而是你自己的ExecStart部分

$ systemctl cat kubelet
# /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=docker.service
Requires=docker.service

[Service]
ExecStart=/usr/local/bin/kubelet \
  --bootstrap-kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
  --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
  --config=/etc/kubernetes/kubelet-conf.yml \
  --hostname-override=k8s-m1 \
  --pod-infra-container-image=100.64.2.62:9999/pause-amd64:3.1 \
  --allow-privileged=true \
  --network-plugin=cni \
  --cni-conf-dir=/etc/cni/net.d \
  --cni-bin-dir=/opt/cni/bin \
  --cert-dir=/etc/kubernetes/pki \
  --logtostderr=false \
  --log-dir=/var/log/kubernetes/kubelet \
  --v=2

Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target

ExecStart的部分复制在终端运行,去掉--logtostderr--log-dir相关的不前台打印日志的选项,--v是日志等级,1-8

官方自带的rpm包啥的kubelet的systemd有环境变量参数,自行命令行export或者使用行内行内环境变量启动

$ /usr/local/bin/kubelet \
  --bootstrap-kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
  --kubeconfig=/etc/kubernetes/kubelet.kubeconfig \
  --config=/etc/kubernetes/kubelet-conf.yml \
  --hostname-override=k8s-m1 \
  --pod-infra-container-image=100.64.2.62:9999/pause-amd64:3.1 \
  --allow-privileged=true \
  --network-plugin=cni \
  --cni-conf-dir=/etc/cni/net.d \
  --cni-bin-dir=/opt/cni/bin \
  --cert-dir=/etc/kubernetes/pki \
  --logtostderr=false \
  --v=2

另外kubelet启动报下面错的话,请开启ipv6

docker_service.go:401] Streaming server stopped unexpectedly: listen tcp [::1]:0: bind: cannot assign requested address

开启ipv6

ansible all -m shell -a 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
sed -ri sed -rn '/f\.[a|d].+ipv6/s#1#0#' /etc/sysctl.d/k8s-sysctl.conf
ansible all -m copy -a 'src=/etc/sysctl.d/k8s-sysctl.conf dest=/etc/sysctl.d/k8s-sysctl.conf'

flanneld

查看参数

$ systemctl cat flanneld
# /usr/lib/systemd/system/flanneld.service
....
Environment=NODE_NAME=k8s-m1
ExecStart=/usr/local/bin/flanneld \
  --kube-subnet-mgr=true \
  --kubeconfig-file=/etc/kubernetes/flanneld.kubeconfig \
  --ip-masq=true \
  --iface=service \
  --public-ip 100.64.2.62 \
  --healthz-ip 100.64.2.62 \
  --healthz-port 8471 \
  --v=2

...

二进制flannel开启前台运行debug同样,不过这里有个Environment,复制ExecStart之前手动export下对应的key=value加环境变量或者下面行内环境变量去debug

NODE_NAME=k8s-m1 /usr/local/bin/flanneld \
  --kube-subnet-mgr=true \
  ......
Clone this wiki locally