HANDBOOK
使用 GitHub Actions 编译 kubernetes 组件
在使用 kubernetes 过程中由于某些需求往往要修改一下 k8s 官方的源码,然后重新编译才行。本文就以修改 kubeadm 生成证书为默认 100 年为例,来讲解如何使用 GitHub Actions 来编译和发布生成的二进制文件。 构建 clone repo 将 kubernetes 官方源码 fork 到自己的 repo 中
1 2 3 4 5 6 |
$ git clone https://github.com/k8sli/kubernetes.git $ cd kubernetes $ git remote add upstream https://github.com/kubernetes/kubernetes.git $ git fetch --all $ git checkout upstream/release-1.21 $ git checkout -B kubeadm-1.21 |
workflow .github/workflows/kubeadm.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
--- name: Build kubeadm binary on: push: tag: - 'v*' jobs: build: runs-on: ubuntu-20.04 # 这里我们选择以 tag 的方式惩触发 job 的运行 if: startsWith(github.ref, 'refs/tags/') steps: - name: Checkout uses: actions/checkout@v2 - name: Build kubeadm binary shell: bash run: | # 运行 build/run.sh 构建脚本来编译相应平台上的二进制文件 build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=linux/amd64 build/run.sh make kubeadm KUBE_BUILD_PLATFORMS=linux/arm64 # 构建好的二进制文件存放在 _output/dockerized/bin/ 中 # 我们根据二进制目标文件的系统名称+CPU体系架构名称进行命名 - name: Prepare for upload shell: bash run: | mv _output/dockerized/bin/linux/amd64/kubeadm kubeadm-linux-amd64 mv _output/dockerized/bin/linux/arm64/kubeadm kubeadm-linux-arm64 sha256sum kubeadm-linux-{amd64,arm64} > sha256sum.txt # 使用 softprops/action-gh-release 来将构建产物上传到 GitHub release 当中 - name: Release and upload packages uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: files: | sha256sum.txt kubeadm-linux-amd64 kubeadm-linux-arm64 |
build/run.sh : Run a command in a build docker container. Common invocations: build/run.sh make: Build just linux binaries in the container. Pass options and Read more…