Closed oomichi closed 5 years ago
kube-build build-127ba8f02e-5-v1.11.2-1 d8e713ce1cb4 About an hour ago 2.3GB
k8s.gcr.io/kube-cross v1.11.2-1 902cf4721f5c 3 months ago 1.7GB
k8s.gcr.io/debian-hyperkube-base-amd64 0.12.0 a6aee83339eb 4 months ago 387MB
k8s.gcr.io/debian-iptables-amd64 v11.0 48319fdf4d25 4 months ago 45.4MB
k8s.gcr.io/debian-base-amd64 0.4.0 8021d54711e6 4 months ago 42.3MB
が増えており、8GB消費していることがわかる。 一方、ログを見ると docker images のクリーンアップ処理はあるようなので、ここに上記のクリーンアップ漏れしているイメージも指定すれば良さそう。
一番大きな kube-build イメージの削除を目指す。 kube-build の作成処理は以下 k/k
438 # Build a docker image from a Dockerfile.
439 # $1 is the name of the image to build
440 # $2 is the location of the "context" directory, with the Dockerfile at the root.
441 # $3 is the value to set the --pull flag for docker build; true by default
442 function kube::build::docker_build() {
443 local -r image=$1
444 local -r context_dir=$2
445 local -r pull="${3:-true}"
446 local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
447
448 kube::log::status "Building Docker image ${image}"
449 local docker_output
450 docker_output=$("${build_cmd[@]}" 2>&1) || {
451 cat <<EOF >&2
452 +++ Docker build command failed for ${image}
453
454 ${docker_output}
455
456 To retry manually, run:
457
458 ${build_cmd[*]}
459
460 EOF
461 return 1
462 }
463 }
で、下記で上記関数を呼出
426 kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
427
428 # Clean up old versions of everything
429 kube::build::docker_delete_old_containers "${KUBE_BUILD_CONTAINER_NAME_BASE}" "${KUBE_BUILD_CONTAINER_NAME}"
430 kube::build::docker_delete_old_containers "${KUBE_RSYNC_CONTAINER_NAME_BASE}" "${KUBE_RSYNC_CONTAINER_NAME}"
431 kube::build::docker_delete_old_containers "${KUBE_DATA_CONTAINER_NAME_BASE}" "${KUBE_DATA_CONTAINER_NAME}"
432 kube::build::docker_delete_old_images "${KUBE_BUILD_IMAGE_REPO}" "${KUBE_BUILD_IMAGE_TAG_BASE}" "${KUBE_BUILD_IMAGE_TAG}"
433
434 kube::build::ensure_data_container
435 kube::build::sync_to_container
436 }
k/kubernetes/pull/74624 で対応。 こちらのチケットはクローズする。
作業メモ
kube-build の使われ方を把握する
+++ [0226 17:32:48] Building Docker image kube-build:build-127ba8f02e-5-v1.11.2-1
+++ [0226 17:34:47] Creating data container kube-build-data-127ba8f02e-5-v1.11.2-1
+++ [0226 17:34:50] Syncing sources to container
+++ [0226 17:35:22] Running build command...
+++ [0226 17:35:33] Building go targets for linux/amd64:
./vendor/k8s.io/code-generator/cmd/deepcopy-gen
+++ [0226 17:35:39] Building go targets for linux/amd64:
./vendor/k8s.io/code-generator/cmd/defaulter-gen
+++ [0226 17:35:43] Building go targets for linux/amd64:
./vendor/k8s.io/code-generator/cmd/conversion-gen
+++ [0226 17:35:48] Building go targets for linux/amd64:
./vendor/k8s.io/kube-openapi/cmd/openapi-gen
2019/02/26 17:35:53 Code for OpenAPI definitions generated
+++ [0226 17:35:53] Building go targets for linux/amd64:
./vendor/github.com/jteeuwen/go-bindata/go-bindata
+++ [0226 17:35:54] Building go targets for linux/amd64:
cmd/kube-proxy
cmd/kube-apiserver
cmd/kube-controller-manager
cmd/cloud-controller-manager
関連ディレクトリは k8s.io/kubernetes/build
release.sh
kube::build::build_image() { - common.sh
kube::build::docker_build
kube::log::status "Building Docker image ${image}"
kube::build::ensure_data_container
kube::build::sync_to_container
kube::log::status "Syncing sources to container"
kube::build::copy_output
kube::log::status "Syncing out of container"
kube::release::package_tarballs
kube::release::package_server_tarballs
kube::log::status "Building tarball: server $platform_tag"
ここにクリーンアップを追加すれば良さそう
他の削除処理
293 kube::log::status "Deleting kube-build image ${KUBE_BUILD_IMAGE}"
294 "${DOCKER[@]}" rmi "${KUBE_BUILD_IMAGE}" &>/dev/null || true
その前に使っているDockerコンテナを削除する必要があり
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1081de8e99d kube-build:build-127ba8f02e-5-v1.11.2-1 "chown -R 0:0 /go/sr・ 3 hours ago Exited (0) 3 hours ago kube-build-data-127ba8f02e-5-v1.11.2-1
e2eバイナリの作成を繰り返していると、ルートファイルシステムの領域を侵食してしまう。 e2eバイナリ作成用のdocker imageからバイナリ取得後、そのdocker imageは不要なはずなのでクリーンアップ処理を追加する。
実行後の状態