调试kubelet
方法1:goland+dlv远程调试kubelet
Goland配置
cd到main函数所在的go文件目录
执行下面命令等待2分钟左右,等待时间长是因为资源不足,直到出现API server listening at: [::]:8033
/root/Downloads/dlv debug --headless --listen=:8033 --api-version=2 -- --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=systemd --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.1 --fail-swap-on=false --logtostderr=false --log-dir=/var/log/kubelet --log-file=/var/log/kubelet/kubelet.log --v=1
代码设置断点后,点击此处debug
方法2:vscode+dlv远程调试kubelet
vscode上安装Remote - SSH插件,用于访问Linux上k8s代码。
.vscode下配置launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "/root/code/go/bin/kubelet",
"env": {},
"args": ["--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf", "--kubeconfig=/etc/kubernetes/kubelet.conf", "--config=/var/lib/kubelet/config.yaml", "--network-plugin=cni", "--pod-infra-container-image=k8s.gcr.io/pause:3.2", "--fail-swap-on=false", "--log-dir=/var/log/kubelet", "--log-file=/var/log/kubelet/kubelet.log", "--v=5", "--logtostderr=false", "--cgroup-driver=systemd"]
}
]
}