安装etcd
hack/install-etcd.sh
export PATH="/home/blue/codes/kubernetes/third_party/etcd:${PATH}"
修改hack/local-up-cluster.sh,出以调试kube-apiserver为例
diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh
index e6195d73383..cfbabc65642 100755
--- a/hack/local-up-cluster.sh
+++ b/hack/local-up-cluster.sh
@@ -550,7 +550,7 @@ EOF
APISERVER_LOG=${LOG_DIR}/kube-apiserver.log
# shellcheck disable=SC2086
- ${CONTROLPLANE_SUDO} "${GO_OUT}/kube-apiserver" "${authorizer_arg}" "${priv_arg}" ${runtime_config} \
+ ${CONTROLPLANE_SUDO} /opt/GoLand-2023.2.5/plugins/go-plugin/lib/dlv/linux/dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec -- "${GO_OUT}/kube-apiserver" "${authorizer_arg}" "${priv_arg}" ${runtime_config} \
${cloud_config_arg} \
"${advertise_address}" \
"${node_port_range}" \
goland中添加golang远程调试配置。
启动本地集群
mkdir -p /var/run/kubernetes/
# 权限改成当前用户
chown -R blue:blue /var/run/kubernetes/
DBG=1 hack/local-up-cluster.sh
在出现这句提示时,点击启动调试按钮
此时等待集群启动完成,如果遇到不能启动,可查看/tmp/kube-apiserver.log找到具体原因。
kubectl --kubeconfig /var/run/kubernetes/admin.kubeconfig…
本地调试kubernetes组件源码方法
发布于