Preload docker images into kic base image

Adds support for specifying kubernetes version and preloading docker
images into the kic base image.

Though this increases the kic base image by ~1.6G, it should improve
start latency in conjunction with removing 'kubeadm pull images' in
another PR.
pull/6531/head
Priya Wadhwa 2020-02-06 13:12:43 -08:00
parent a59846ed61
commit e055ee6929
3 changed files with 59 additions and 13 deletions

View File

@ -19,6 +19,8 @@ VERSION_BUILD ?= 1
RAW_VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).${VERSION_BUILD}
VERSION ?= v$(RAW_VERSION)
KUBERNETES_VERSION ?= $(shell cat pkg/minikube/constants/constants.go | grep "DefaultKubernetesVersion =" | cut -d ' ' -f4 | sed 's/"//g')
# Default to .0 for higher cache hit rates, as build increments typically don't require new ISO versions
ISO_VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).0
# Dashes are valid in semver, but not Linux packaging. Use ~ to delimit alpha/beta
@ -500,10 +502,13 @@ storage-provisioner-image: out/storage-provisioner-$(GOARCH) ## Build storage-pr
docker build -t $(STORAGE_PROVISIONER_IMAGE) -f deploy/storage-provisioner/Dockerfile --build-arg arch=$(GOARCH) .
.PHONY: kic-base-image
kic-base-image: ## builds the base image used for kic.
docker rmi -f $(REGISTRY)/kicbase:v0.0.5-snapshot || true
docker build -f ./hack/images/kicbase.Dockerfile -t $(REGISTRY)/kicbase:v0.0.5-snapshot --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) .
kic-base-image: generate-preloaded-images-tar ## builds the base image used for kic.
docker rmi -f $(REGISTRY)/kicbase:v0.0.5-k8s-${KUBERNETES_VERSION} || true
docker build -f ./hack/images/kicbase.Dockerfile -t $(REGISTRY)/kicbase:v0.0.5-k8s-${KUBERNETES_VERSION} --build-arg COMMIT_SHA=${VERSION}-$(COMMIT) --build-arg KUBERNETES_VERSION=${KUBERNETES_VERSION} .
.PHONY: generate-preloaded-images-tar
generate-preloaded-images-tar: out/minikube
KUBERNETES_VERSION=${KUBERNETES_VERSION} ./hack/preload-images/generate-preloaded-images-tar.sh
.PHONY: push-storage-provisioner-image

View File

@ -2,7 +2,7 @@ ARG COMMIT_SHA
# using base image created by kind https://github.com/kubernetes-sigs/kind
# which is an ubuntu 19.10 with an entry-point that helps running systemd
# could be changed to any debian that can run systemd
FROM kindest/base:v20200122-2dfe64b2
FROM kindest/base:v20200122-2dfe64b2 as base
USER root
RUN apt-get update && apt-get install -y \
sudo \
@ -34,12 +34,21 @@ USER root
# https://github.com/kubernetes-sigs/kind/blob/master/images/base/files/usr/local/bin/entrypoint
RUN mkdir -p /kind
RUN rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/* \
/usr/share/doc/* \
/usr/share/man/* \
/usr/share/local/* \
RUN echo "kic! Build: ${COMMIT_SHA} Time :$(date)" > "/kic.txt"
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/* \
/usr/share/doc/* \
/usr/share/man/* \
/usr/share/local/* \
RUN echo "kic! Build: ${COMMIT_SHA} Time :$(date)" > "/kic.txt"
FROM busybox
ARG KUBERNETES_VERSION
COPY out/preloaded-images-k8s-$KUBERNETES_VERSION.tar /preloaded-images.tar
RUN tar xvf /preloaded-images.tar -C /
FROM base
COPY --from=1 /var/lib/docker /var/lib/docker

View File

@ -0,0 +1,32 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# 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.
set -ex
PROFILE=generate-preloaded-images-tar
KUBERNETES_VERSION=${KUBERNETES_VERSION:-""}
TARBALL_FILENAME=preloaded-images-k8s-$KUBERNETES_VERSION.tar
function delete_minikube {
out/minikube delete --profile=$PROFILE
}
trap "delete_minikube" ERR
out/minikube start --memory=10000 --profile=$PROFILE --kubernetes-version=$KUBERNETES_VERSION
out/minikube ssh --profile=$PROFILE -- sudo tar cvf $TARBALL_FILENAME /var/lib/docker
scp -o StrictHostKeyChecking=no -i $(out/minikube ssh-key --profile=$PROFILE) docker@$(out/minikube ip --profile=$PROFILE):/home/docker/$TARBALL_FILENAME out/$TARBALL_FILENAME
delete_minikube