Files
kind/images/base/Dockerfile

123 lines
6.0 KiB
Docker
Raw Normal View History

2018-07-23 10:06:37 -07:00
# Copyright 2018 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.
2019-10-23 10:12:20 -07:00
# kind node base image
2018-07-23 10:06:37 -07:00
#
# For systemd + docker configuration used below, see the following references:
# https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
2019-10-23 10:12:20 -07:00
# start from ubuntu 19.10, this image is reasonably small as a starting point
# for a kubernetes node image, it doesn't contain much we don't need
FROM ubuntu:20.04
2018-07-23 10:06:37 -07:00
2019-10-23 10:12:20 -07:00
# Configure containerd and runc binaries from kind-ci/containerd-nightlies repository
# The repository contains latest stable releases and nightlies built for multiple architectures
2020-02-26 18:04:57 -08:00
ARG CONTAINERD_VERSION="v1.3.3-14-g449e9269"
2019-10-23 10:12:20 -07:00
# Configure CNI binaries from upstream
2020-01-22 17:33:18 -08:00
ARG CNI_VERSION="v0.8.5"
2019-10-23 10:12:20 -07:00
# Configure crictl binary from upstream
2020-04-30 21:00:18 -07:00
ARG CRICTL_VERSION="v1.18.0"
2019-10-23 10:12:20 -07:00
# copy in static files (configs, scripts)
COPY files/ /
2019-10-23 10:12:20 -07:00
# Install dependencies, first from apt, then from release tarballs.
# NOTE: we use one RUN to minimize layers.
#
# First we must ensure that our util scripts are executable.
#
# The base image already has: ssh, apt, snapd, but we need to install more packages.
# Packages installed are broken down into (each on a line):
2018-07-23 10:06:37 -07:00
# - packages needed to run services (systemd)
2019-04-09 11:49:23 -07:00
# - packages needed for kubernetes components
# - packages needed by the container runtime
2019-04-09 11:49:23 -07:00
# - misc packages kind uses itself
2019-10-23 10:12:20 -07:00
# After installing packages we cleanup by:
2019-10-23 13:33:20 -07:00
# - removing unwanted systemd services
2019-10-23 10:12:20 -07:00
# - disabling kmsg in journald (these log entries would be confusing)
2019-05-02 22:04:05 -07:00
#
2019-10-23 10:12:20 -07:00
# Then we install containerd from our nightly build infrastructure, as this
# build for multiple architectures and allows us to upgrade to patched releases
# more quickly.
2019-05-02 22:04:05 -07:00
#
2019-10-23 10:12:20 -07:00
# Next we download and extract crictl and CNI plugin binaries from upstream.
2019-05-02 22:04:05 -07:00
#
2019-11-05 15:42:11 -08:00
# Next we ensure the /etc/kubernetes/manifests directory exists. Normally
2019-10-23 10:12:20 -07:00
# a kubeadm debain / rpm package would ensure that this exists but we install
# freshly built binaries directly when we build the node image.
2019-11-05 15:42:11 -08:00
#
# Finally we adjust tempfiles cleanup to be 1 minute after "boot" instead of 15m
# This is plenty after we've done initial setup for a node, but before we are
# likely to try to export logs etc.
2019-10-23 10:12:20 -07:00
RUN echo "Ensuring scripts are executable ..." \
&& chmod +x /usr/local/bin/clean-install /usr/local/bin/entrypoint \
&& echo "Installing Packages ..." \
&& DEBIAN_FRONTEND=noninteractive clean-install \
systemd \
2019-04-09 11:49:23 -07:00
conntrack iptables iproute2 ethtool socat util-linux mount ebtables udev kmod \
libseccomp2 \
2019-04-09 11:49:23 -07:00
bash ca-certificates curl rsync \
2018-07-23 10:06:37 -07:00
&& find /lib/systemd/system/sysinit.target.wants/ -name "systemd-tmpfiles-setup.service" -delete \
&& rm -f /lib/systemd/system/multi-user.target.wants/* \
&& rm -f /etc/systemd/system/*.wants/* \
&& rm -f /lib/systemd/system/local-fs.target.wants/* \
&& rm -f /lib/systemd/system/sockets.target.wants/*udev* \
&& rm -f /lib/systemd/system/sockets.target.wants/*initctl* \
&& rm -f /lib/systemd/system/basic.target.wants/* \
2019-04-09 11:49:23 -07:00
&& echo "ReadKMsg=no" >> /etc/systemd/journald.conf \
&& ln -s "$(which systemd)" /sbin/init \
2019-10-23 10:12:20 -07:00
&& echo "Installing containerd ..." \
&& export ARCH=$(dpkg --print-architecture | sed 's/ppc64el/ppc64le/' | sed 's/armhf/arm/') \
&& export CONTAINERD_BASE_URL="https://github.com/kind-ci/containerd-nightlies/releases/download/containerd-${CONTAINERD_VERSION#v}" \
&& curl -sSL --retry 5 --output /tmp/containerd.tgz "${CONTAINERD_BASE_URL}/containerd-${CONTAINERD_VERSION#v}.linux-${ARCH}.tar.gz" \
&& tar -C /usr/local -xzvf /tmp/containerd.tgz \
2019-10-04 17:18:56 +02:00
&& rm -rf /tmp/containerd.tgz \
&& rm -f /usr/local/bin/containerd-stress /usr/local/bin/containerd-shim-runc-v1 \
2019-10-23 10:12:20 -07:00
&& curl -sSL --retry 5 --output /usr/local/sbin/runc "${CONTAINERD_BASE_URL}/runc.${ARCH}" \
&& chmod 755 /usr/local/sbin/runc \
2019-10-23 10:12:20 -07:00
&& containerd --version \
&& systemctl enable containerd \
&& echo "Installing crictl ..." \
&& curl -fSL "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" | tar xzC /usr/local/bin \
&& echo "Installing CNI binaries ..." \
&& export ARCH=$(dpkg --print-architecture | sed 's/ppc64el/ppc64le/' | sed 's/armhf/arm/') \
2019-09-26 18:27:23 -07:00
&& export CNI_TARBALL="${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz" \
2019-10-23 10:12:20 -07:00
&& export CNI_URL="https://github.com/containernetworking/plugins/releases/download/${CNI_TARBALL}" \
&& curl -sSL --retry 5 --output /tmp/cni.tgz "${CNI_URL}" \
2018-07-23 10:06:37 -07:00
&& mkdir -p /opt/cni/bin \
&& tar -C /opt/cni/bin -xzf /tmp/cni.tgz \
2019-10-23 10:12:20 -07:00
&& rm -rf /tmp/cni.tgz \
2019-12-19 16:13:43 -08:00
&& find /opt/cni/bin -type f -not \( \
-iname host-local \
-o -iname ptp \
-o -iname portmap \
-o -iname loopback \
\) \
-delete \
2019-10-23 10:12:20 -07:00
&& echo "Ensuring /etc/kubernetes/manifests" \
2019-11-05 15:42:11 -08:00
&& mkdir -p /etc/kubernetes/manifests \
&& echo "Adjusting systemd-tmpfiles timer" \
2020-04-26 20:51:29 -07:00
&& sed -i /usr/lib/systemd/system/systemd-tmpfiles-clean.timer -e 's#OnBootSec=.*#OnBootSec=1min#' \
&& echo "Modifying /etc/nsswitch.conf to prefer hosts" \
&& sed -i /etc/nsswitch.conf -re 's#^(hosts:\s*).*#\1dns files#'
2019-04-09 11:49:23 -07:00
2018-07-23 10:06:37 -07:00
# tell systemd that it is in docker (it will check for the container env)
# https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
ENV container docker
# systemd exits on SIGRTMIN+3, not SIGTERM (which re-executes it)
# https://bugzilla.redhat.com/show_bug.cgi?id=1201657
STOPSIGNAL SIGRTMIN+3
2019-10-23 10:12:20 -07:00
# NOTE: this is *only* for documentation, the entrypoint is overridden later
2018-09-04 19:53:00 -07:00
ENTRYPOINT [ "/usr/local/bin/entrypoint", "/sbin/init" ]