├── README.md ├── install-containerd-for-kubernetes.md └── k2-1-script-of-k8s-devenv-setup.md /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes 系列视频的文档资料 2 | 录了一些列和Kubernetes源码以及二次开发相关的视频,发在[Bilibili上](https://space.bilibili.com/1748865719)。这里主要存放相关文档,例如脚本列表,需要结合视频使用。 -------------------------------------------------------------------------------- /install-containerd-for-kubernetes.md: -------------------------------------------------------------------------------- 1 | # Install containerd in Ubuntu 22.04 for Kubernetes 2 | 3 | Docker isn't mandatory to run kubernetes since 1.20, this guid list docs about how to install containerd instead of docker 4 | 5 | ## main starting point: 6 | https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd 7 | 8 | ## run containerd with systemd 9 | The containerd.service can be used for launching containerd, the script is provided by containerd github rep: 10 | https://github.com/containerd/containerd/blob/main/containerd.service 11 | -------------------------------------------------------------------------------- /k2-1-script-of-k8s-devenv-setup.md: -------------------------------------------------------------------------------- 1 | # 安装 Kubernetes 开发环境的脚本 2 | 3 | 在 [Kubernetes开发之旅 第一阶段](https://www.bilibili.com/video/BV11U4y1y7V7/),我系统介绍了如何在Ubuntu 20.04 Desktop版本中安装Kubernetes 1.24.0的开发环境,这篇文档给出其中用到的脚本命令,不适合直接阅读,请结合以上视频使用。 4 | 5 | ## 为Ubuntu换阿里源 6 | ```sh 7 | sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak 8 | sudo nano /etc/apt/sources.list 9 | ``` 10 | 用如下阿里源替换该文件的已有内容: 11 | ```sh 12 | deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse 13 | deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse 14 | deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse 15 | deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse 16 | deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse 17 | deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse 18 | deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse 19 | deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse 20 | deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse 21 | deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse 22 | 23 | sudo apt-get update 24 | ``` 25 | 26 | ## 安装GNU 27 | ```sh 28 | sudo apt install build-essential 29 | ``` 30 | 31 | ## 安装Docker 32 | ```sh 33 | sudo apt-get update 34 | sudo apt-get install \ 35 | ca-certificates \ 36 | curl \ 37 | gnupg \ 38 | lsb-release 39 | 40 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 41 | 42 | echo \ 43 | "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ 44 | $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 45 | 46 | sudo apt-get update 47 | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin 48 | ``` 49 | 50 | ## 修改ContainerD 所用的镜像库地址 51 | ```sh 52 | containerd config default > ~/config.toml 53 | ``` 54 | 然后编辑~config.toml去添加信息,具体内容请看视频中这个环节 55 | ```sh 56 | sudo mv ~/config.toml /etc/containerd/config.toml 57 | sudo systemctl restart containerd 58 | ``` 59 | 60 | ## 安装rsync: 61 | ```sh 62 | cd ~/Downloads 63 | wget https://github.com/WayneD/rsync/archive/refs/tags/v3.2.4.tar.gz 64 | tar -xf v3.2.4.tar.gz 65 | cd rsync-3.2.4 66 | ``` 67 | 安装一些工具包 68 | ```sh 69 | sudo apt install -y gcc g++ gawk autoconf automake python3-cmarkgfm 70 | sudo apt install -y acl libacl1-dev 71 | sudo apt install -y attr libattr1-dev 72 | sudo apt install -y libxxhash-dev 73 | sudo apt install -y libzstd-dev 74 | sudo apt install -y liblz4-dev 75 | sudo apt install -y libssl-dev 76 | ``` 77 | 编译,安装 78 | ```sh 79 | ./configure 80 | make 81 | sudo cp ./rsync /usr/local/bin/ 82 | sudo cp ./rsync-ssl /usr/local/bin/ 83 | ``` 84 | 85 | ## 安装jq: 86 | ```sh 87 | sudo apt-get install jq 88 | ``` 89 | 90 | ## 安装pyyaml: 91 | sudo apt install python3-pip 92 | pip install pyyaml 93 | 94 | ## 安装etcd: 95 | ```sh 96 | ETCD_VER=v3.5.4 97 | curl -L https://storage.googleapis.com/etcd/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz 98 | mkdir ~/etcd 99 | tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C ~/etcd --strip-components=1 100 | rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz 101 | 102 | sudo nano ~/.bashrc 103 | ``` 104 | 最后加入:export PATH="/home/<用户名>/etcd:${PATH}" 105 | ```sh 106 | source ~/.bashrc 107 | ``` 108 | 109 | ## 安装golang (1.24及以上需要golang 1.18): 110 | ```sh 111 | cd ~/Downloads 112 | wget https://golang.google.cn/dl/go1.18.2.linux-amd64.tar.gz 113 | sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz 114 | 115 | mkdir ~/go 116 | mkdir ~/go/src 117 | mkdir ~/go/bin 118 | sudo nano ~/.bashrc 119 | ``` 120 | 最后加入如下几行: 121 | ```sh 122 | export GOPATH="/home/<用户名>/go" 123 | export GOBIN="/home/<用户名>/go/bin" 124 | export PATH="/usr/local/go/bin:$GOPATH/bin:${PATH}" 125 | 126 | source ~/.bashrc 127 | 128 | sudo nano /etc/sudoers 129 | ``` 130 | 在secure_path一行加入如下目录: 131 | /usr/local/go/bin (这个是$GOPATH/bin目录) 132 | /home/<用户名>/etcd (这个是etcd命令所在目录) 133 | /home/<用户名>/go/bin (这个是go get安装的程序所在位置) 134 | 135 | ### 设置golang代理: 136 | ```sh 137 | go env -w GO111MODULE="on" 138 | go env -w GOPROXY="https://goproxy.cn,direct" 139 | ``` 140 | 141 | ## 安装CFSSL: 142 | ```sh 143 | go install github.com/cloudflare/cfssl/cmd/...@latest 144 | ``` 145 | 146 | ## 下载kubernetes代码: 147 | ```sh 148 | mkdir $GOPATH/src/k8s.io && cd $GOPATH/src/k8s.io 149 | git clone https://github.com/kubernetes/kubernetes.git 150 | git checkout -b kube1.24 v1.24.0 151 | ``` 152 | 153 | ## 编译启动本地单节点集群: 154 | ```sh 155 | cd $GOPATH/src/k8s.io/kubernetes 156 | 编译单个组建:sudo make WHAT="cmd/kube-apiserver" 157 | 编译所有组件:sudo make all 158 | 启动本地单节点集群: sudo ./hack/local-up-cluster.sh 159 | ``` 160 | 161 | ## 开启本地debug功能 162 | 163 | ```sh 164 | cd $GOPATH/src/k8s.io/kubernetes 165 | # kubernetes go编译文件 166 | sudo vi ./hack/lib/golang.sh 167 | # 查找build_binaries()函数 vi语法 168 | :/build_binaries() 169 | ``` 170 | 171 | ### 找到一下bebug判断,注释,一直开启debug能力 172 | 173 | > ```sh 174 | > gogcflags="all=-trimpath=${trimroot} ${GOGCFLAGS:-}" 175 | > if [[ "${DBG:-}" == 1 ]]; then 176 | > # Debugging - disable optimizations and inlining. 177 | > gogcflags="${gogcflags} -N -l" 178 | > fi 179 | > 180 | > goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}" 181 | > if [[ "${DBG:-}" != 1 ]]; then 182 | > # Not debugging - disable symbols and DWARF. 183 | > goldflags="${goldflags} -s -w" 184 | > fi 185 | > ``` 186 | > 187 | > 注释判断,将debug直接放在下面, 再保存即可 188 | > 189 | > ```sh 190 | > gogcflags="all=-trimpath=${trimroot} ${GOGCFLAGS:-}" 191 | > # if [[ "${DBG:-}" == 1 ]]; then 192 | > # # Debugging - disable optimizations and inlining. 193 | > # gogcflags="${gogcflags} -N -l" 194 | > # fi 195 | > gogcflags="${gogcflags} -N -l" 196 | > goldflags="all=$(kube::version::ldflags) ${GOLDFLAGS:-}" 197 | > # if [[ "${DBG:-}" != 1 ]]; then 198 | > # # Not debugging - disable symbols and DWARF. 199 | > # goldflags="${goldflags} -s -w" 200 | > # fi 201 | > ``` --------------------------------------------------------------------------------