使用VS code 调试 Kubernetes 源代码

请参照 我的另一篇文章 使用 VS Code 阅读 Kubernetes 代码 配置好环境

打开Shell 并且设置 GOPATH 和 GOROOT

export GOPATH=~/k8s
export GOROOT=/usr/local/go

安装Delve和其他Go 工具

go get -u -v github.com/derekparker/delve/cmd/dlv
go get -u -v github.com/ramya-rao-a/go-outline  
go get -u -v github.com/acroca/go-symbols   
go get -u -v github.com/nsf/gocode  
go get -u -v github.com/rogpeppe/godef  
go get -u -v golang.org/x/tools/cmd/godoc   
go get -u -v github.com/zmb3/gogetdoc   
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/fatih/gomodifytags
go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v github.com/cweill/gotests/...
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/josharian/impl
go get -u -v github.com/haya14busa/goplay/cmd/goplay
使用 VS Code打开代码

code $GOPATH

设置断点

~/k8s/src/k8s.io/kubernetes/cmd/hyperkube/main.go 

114行

编辑 launch.json, 

下面的示例开始调试Kubelet, 请替换 ReplaceWithYourName 为系统当前的用户名


{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "/home/ReplaceWithYourName/k8s/src/k8s.io/kubernetes/cmd/hyperkube/hyperkube",
            "env": {},
            "args": ["kubelet",
            "--cluster-dns=10.96.0.10",
            "--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf",
            "--kubeconfig=/etc/kubernetes/kubelet.conf",
            "--v=2"],
            "showLog": true
        }
    ]
}

F5 开始调试

使用VS code 调试 Kubernetes 源代码_第1张图片


你可能感兴趣的:(Kubernetes)