Kubernetes Build 總結(jié)以及問題

本文介紹Kubernetes編譯的過程既鞠。
參考:
https://kubernetes.io/docs/setup/release/building-from-source/
https://github.com/kubernetes/kubernetes/tree/master/build/

1 下載源代碼

https://github.com/kubernetes/kubernetes/releases/tag/v1.13.3

下載Source code(tar.gz) 到有Docker的環(huán)境捉片,并解壓縮巴刻。


image.png

2 編譯

Key scripts
The following scripts are found in the build/ directory. Note that all scripts must be run from the Kubernetes root directory.

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 packages as necessary.
build/run.sh make cross: Build all binaries for all platforms
build/run.sh make kubectl KUBE_BUILD_PLATFORMS=darwin/amd64: Build the specific binary for the specific platform (kubectl and darwin/amd64 respectively in this example)
build/run.sh make test: Run all unit tests
build/run.sh make test-integration: Run integration test
build/run.sh make test-cmd: Run CLI tests
build/copy-output.sh: This will copy the contents of _output/dockerized/bin from the Docker container to the local _output/dockerized/bin. It will also copy out specific file patterns that are generated as part of the build process. This is run automatically as part of build/run.sh.
build/make-clean.sh: Clean out the contents of _output, remove any locally built container images and remove the data container.
build/shell.sh: Drop into a bash shell in a build container with a snapshot of the current repo code.

以編譯Linux平臺kubectl 為例:

[root@VM_0_4_centos kubernetes-1.13.3]# build/run.sh make kubectl 
+++ [0216 11:19:07] Verifying Prerequisites....
+++ [0216 11:19:07] Building Docker image kube-build:build-d7e9f7306e-5-v1.11.5-1
+++ Docker build command failed for kube-build:build-d7e9f7306e-5-v1.11.5-1

Sending build context to Docker daemon  8.704kB
Step 1/16 : FROM k8s.gcr.io/kube-cross:v1.11.5-1
Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

To retry manually, run:

docker build -t kube-build:build-d7e9f7306e-5-v1.11.5-1 --pull=false /root/Sandbox/kubernetes-1.13.3/_output/images/kube-build:build-d7e9f7306e-5-v1.11.5-1

!!! [0216 11:19:22] Call tree:
!!! [0216 11:19:22]  1: build/run.sh:31 kube::build::build_image(...)
!!! Error in build/../build/common.sh:461
  Error in build/../build/common.sh:461. '((i<3-1))' exited with status 1
Call stack:
  1: build/../build/common.sh:461 kube::build::build_image(...)
  2: build/run.sh:31 main(...)
Exiting with status 1

遇到上述問題的原因是:
k8s.gcr.io/kube-cross:v1.11.5-1在中國區(qū)被墻赤屋,無法下載。
解決辦法是:
到DockerHub上找到googlecontainer/kube-cross抗斤,并下載指定Tag的image世吨,下載后重新執(zhí)行docker tag打標(biāo)簽。


kube-cross image
kube-cross image tag list
[root@VM_0_4_centos kubernetes-1.13.3]# docker pull googlecontainer/kube-cross:v1.11.5-1
v1.11.5-1: Pulling from googlecontainer/kube-cross
ab1fc7e4bf91: Pull complete 
35fba333ff52: Pull complete 
f0cb1fa13079: Pull complete 
3d1dd648b5ad: Pull complete 
866ed2e2b1fe: Pull complete 
ddc4ad35a2f0: Pull complete 
ab8da8d8889d: Pull complete 
bc09b85f7ce1: Pull complete 
771b92c72d72: Pull complete 
a197f22cc074: Pull complete 
c09a2f634954: Pull complete 
e99d87f11b4a: Pull complete 
817e550ce839: Pull complete 
7489af17a433: Pull complete 
Digest: sha256:b4864400d58268b3abde3d9ded4ab23a9ddda6c85d63c80ed536cd2810d75042
Status: Downloaded newer image for googlecontainer/kube-cross:v1.11.5-1

重新打Tag:

[root@VM_0_4_centos kubernetes-1.13.3]# docker help tag

Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Options:

[root@VM_0_4_centos kubernetes-1.13.3]# docker tag googlecontainer/kube-cross:v1.11.5-1 k8s.gcr.io/kube-cross:v1.11.5-1
[root@VM_0_4_centos kubernetes-1.13.3]# docker images |grep kube-cross
googlecontainer/kube-cross                                 v1.11.5-1           b16987a9b305        3 weeks ago         1.75GB
k8s.gcr.io/kube-cross                                      v1.11.5-1           b16987a9b305        3 weeks ago         1.75GB

現(xiàn)在重新開始編譯:

[root@VM_0_4_centos kubernetes-1.13.3]# build/run.sh make kubectl 
...
I0216 11:40:12.554451    3183 api_linter.go:109] validating API rules for type k8s.io/metrics/pkg/apis/metrics/v1beta1.valueToStringGenerated
I0216 11:40:12.554455    3183 api_linter.go:192] validating API rule names_match for type k8s.io/metrics/pkg/apis/metrics/v1beta1.valueToStringGenerated
I0216 11:40:12.554460    3183 api_linter.go:192] validating API rule omitempty_match_case for type k8s.io/metrics/pkg/apis/metrics/v1beta1.valueToStringGenerated
I0216 11:40:12.554636    3183 execute.go:67] Assembling file "/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/generated/openapi/zz_generated.openapi.go"
I0216 11:40:14.087868    3183 api_linter.go:44] Assembling file "_output/violations.report"
2019/02/16 11:40:14 Code for OpenAPI definitions generated
Go version: go version go1.11.5 linux/amd64
+++ [0216 11:40:14] Building go targets for linux/amd64:
    ./vendor/github.com/jteeuwen/go-bindata/go-bindata
Env for linux/amd64: GOOS=linux GOARCH=amd64 GOROOT=/usr/local/go CGO_ENABLED= CC=
Coverage is disabled.
+++ [0216 11:40:14] Placing binaries
Generated bindata file : test/e2e/generated/bindata.go has 9052 test/e2e/generated/bindata.go lines of lovely automated artifacts
No changes in generated bindata file: pkg/kubectl/generated/bindata.go
Go version: go version go1.11.5 linux/amd64
+++ [0216 11:40:15] Building go targets for linux/amd64:
    cmd/kubectl
Env for linux/amd64: GOOS=linux GOARCH=amd64 GOROOT=/usr/local/go CGO_ENABLED= CC=
Coverage is disabled.
+++ [0216 11:40:51] Placing binaries
+++ [0216 11:40:52] Syncing out of container
+++ [0216 11:40:52] Stopping any currently running rsyncd container
+++ [0216 11:40:52] Starting rsyncd container
+++ [0216 11:40:53] Running rsync
+++ [0216 11:40:54] Stopping any currently running rsyncd container
[root@VM_0_4_centos kubernetes-1.13.3]# ls

用于Build的環(huán)境基于如下Dockerfile構(gòu)建:

[root@VM_0_4_centos kubernetes-1.13.3]# cat _output/images/kube-build:build-d7e9f7306e-5-v1.11.5-1/Dockerfile
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file creates a standard build environment for building Kubernetes
FROM k8s.gcr.io/kube-cross:v1.11.5-1

# Mark this as a kube-build container
RUN touch /kube-build-image

# To run as non-root we sometimes need to rebuild go stdlib packages.
RUN chmod -R a+rwx /usr/local/go/pkg

# For running integration tests /var/run/kubernetes is required
# and should be writable by user
RUN mkdir /var/run/kubernetes && chmod a+rwx /var/run/kubernetes

# The kubernetes source is expected to be mounted here.  This will be the base
# of operations.
ENV HOME /go/src/k8s.io/kubernetes
WORKDIR ${HOME}

# Make output from the dockerized build go someplace else
ENV KUBE_OUTPUT_SUBPATH _output/dockerized

# Pick up version stuff here as we don't copy our .git over.
ENV KUBE_GIT_VERSION_FILE ${HOME}/.dockerized-kube-version-defs

# Add system-wide git user information
RUN git config --system user.email "nobody@k8s.io" \
  && git config --system user.name "kube-build-image"

# Fix permissions on gopath
RUN chmod -R a+rwx $GOPATH

# Make log messages use the right timezone
ADD localtime /etc/localtime
RUN chmod a+r /etc/localtime

# Set up rsyncd
ADD rsyncd.password /
RUN chmod a+r /rsyncd.password
ADD rsyncd.sh /
RUN chmod a+rx /rsyncd.sh

參照如下操作驶臊,將編譯好的文件從容器copy到本地:

build/copy-output.sh: This will copy the contents of _output/dockerized/bin from the Docker container to the local _output/dockerized/bin. It will also copy out specific file patterns that are generated as part of the build process. This is run automatically as part of build/run.sh.
[root@VM_0_4_centos kubernetes-1.13.3]# build/copy-output.sh
+++ [0216 11:50:08] Verifying Prerequisites....
+++ [0216 11:50:08] Syncing out of container
+++ [0216 11:50:08] Stopping any currently running rsyncd container
+++ [0216 11:50:08] Starting rsyncd container
+++ [0216 11:50:08] Running rsync
+++ [0216 11:50:09] Stopping any currently running rsyncd container

[root@VM_0_4_centos kubernetes-1.13.3]# ll _output/dockerized/bin/linux/amd64/
total 71800
-rwxr-xr-x 1 root root  5800256 Feb 16 11:39 conversion-gen
-rwxr-xr-x 1 root root  5791968 Feb 16 11:38 deepcopy-gen
-rwxr-xr-x 1 root root  5783808 Feb 16 11:38 defaulter-gen
-rwxr-xr-x 1 root root  4460824 Feb 16 11:38 go2make
-rwxr-xr-x 1 root root  2001888 Feb 16 11:40 go-bindata
-rwxr-xr-x 1 root root 39185888 Feb 16 11:40 kubectl
-rwxr-xr-x 1 root root 10363744 Feb 16 11:40 openapi-gen

[root@VM_0_4_centos kubernetes-1.13.3]# _output/dockerized/bin/linux/amd64/kubectl  version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"archive", BuildDate:"2019-02-16T03:40:15Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.5-tke.3", GitCommit:"53e244be925234190938376fe8637189b6caf125", GitTreeState:"clean", BuildDate:"2018-12-04T04:10:15Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

從執(zhí)行kubectl version的結(jié)果可以看到kubectl可以工作挪挤,版本是v1.13.3。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末关翎,一起剝皮案震驚了整個濱河市扛门,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌纵寝,老刑警劉巖论寨,帶你破解...
    沈念sama閱讀 217,826評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異爽茴,居然都是意外死亡葬凳,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評論 3 395
  • 文/潘曉璐 我一進店門室奏,熙熙樓的掌柜王于貴愁眉苦臉地迎上來火焰,“玉大人,你說我怎么就攤上這事胧沫〔颍” “怎么了?”我有些...
    開封第一講書人閱讀 164,234評論 0 354
  • 文/不壞的土叔 我叫張陵绒怨,是天一觀的道長纯赎。 經(jīng)常有香客問我,道長南蹂,這世上最難降的妖魔是什么犬金? 我笑而不...
    開封第一講書人閱讀 58,562評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上晚顷,老公的妹妹穿的比我還像新娘峰伙。我一直安慰自己,他們只是感情好音同,可當(dāng)我...
    茶點故事閱讀 67,611評論 6 392
  • 文/花漫 我一把揭開白布词爬。 她就那樣靜靜地躺著,像睡著了一般权均。 火紅的嫁衣襯著肌膚如雪顿膨。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,482評論 1 302
  • 那天叽赊,我揣著相機與錄音恋沃,去河邊找鬼。 笑死必指,一個胖子當(dāng)著我的面吹牛囊咏,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播塔橡,決...
    沈念sama閱讀 40,271評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼梅割,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了葛家?” 一聲冷哼從身側(cè)響起户辞,我...
    開封第一講書人閱讀 39,166評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎癞谒,沒想到半個月后底燎,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,608評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡弹砚,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,814評論 3 336
  • 正文 我和宋清朗相戀三年双仍,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片桌吃。...
    茶點故事閱讀 39,926評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡朱沃,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出茅诱,到底是詐尸還是另有隱情为流,我是刑警寧澤,帶...
    沈念sama閱讀 35,644評論 5 346
  • 正文 年R本政府宣布让簿,位于F島的核電站,受9級特大地震影響秀睛,放射性物質(zhì)發(fā)生泄漏尔当。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,249評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望椭迎。 院中可真熱鬧锐帜,春花似錦、人聲如沸畜号。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽简软。三九已至蛮拔,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間痹升,已是汗流浹背建炫。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留疼蛾,地道東北人肛跌。 一個月前我還...
    沈念sama閱讀 48,063評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像察郁,于是被迫代替她去往敵國和親衍慎。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,871評論 2 354

推薦閱讀更多精彩內(nèi)容