1. 使用 vs-code 来阅读源码

1. 下载源码

地址:https://github.com/kubernetes/kubernetes/releases/tag/v1.25.15

版本自己选择。

下载到本地目录,如:

k8s-1.25 目录下创建 src/k8s.io 目录,注意目录层次,.githubsrc/k8s.io 下。

<br>

2. 使用 vscode

使用 vscode 打开 D:\code\k8s-1.25\src\k8s.io 目录,这时会提示我们下载 go 库,按照提示下载按照即可。安装完成后,打开 cmd,修改镜像源:

go env -w GOPROXY=https://goproxy.io/

接着重启 vscode,这时会提醒我们下载更多依赖库,按照提示下载按照即可。

Installing 8 tools at C:\Go\repository\bin in module mode.
  gotests
  gomodifytags
  impl
  goplay
  dlv
  staticcheck
  gopls
  go-outline
 
Installing github.com/cweill/gotests/gotests@latest (C:\Go\repository\bin\gotests.exe) SUCCEEDED
Installing github.com/fatih/gomodifytags@latest (C:\Go\repository\bin\gomodifytags.exe) SUCCEEDED
Installing github.com/josharian/impl@latest (C:\Go\repository\bin\impl.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (C:\Go\repository\bin\dlv.exe) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay@latest (C:\Go\repository\bin\goplay.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (C:\Go\repository\bin\dlv.exe) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (C:\Go\repository\bin\staticcheck.exe) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (C:\Go\repository\bin\staticcheck.exe) SUCCEEDED

<br>

3. 添加环境变量 GOPATH

我的电脑 -> 属性 -> 高级系统设置 -> 环境变量,添加如下形式 D:\code\k8s-1.25\src\k8s.io\vendor

然后 kubernetes 本身是支持 gomod 的,但源码这里提供了所有的依赖在 staging/src/k8s.io/ 目录下,可以将此目录内的文件复制到 vendor/k8s.io 目录下即可。

然后重启 vscode,就完成了。

Kubernetes源码阅读 文章被收录于专栏

Kubernetes源码阅读

全部评论

相关推荐

点赞 评论 收藏
分享
前两题写得快,最后一题也只会个暴力,结束笔试
洛水为天依:第三题卡在了71%,实在看不出来错哪了直接交卷了
投递米哈游等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务