2020-09-27 13:00:33 +00: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.
# kind node base image
#
# For systemd + docker configuration used below, see the following references:
2020-10-22 21:55:06 +00:00
# https://systemd.io/CONTAINER_INTERFACE/
2020-09-27 13:00:33 +00:00
2021-06-22 21:49:53 +00:00
# multi-tage docker build so we can build auto-pause for arm64
FROM golang:1.16
WORKDIR /src
# becaue auto-pause binary depends on minikube's code we need to pass the whole source code as the context
ADD . .
RUN cd ./cmd/auto-pause/ && go build
2020-09-27 13:00:33 +00:00
# start from ubuntu 20.04, this image is reasonably small as a starting point
# for a kubernetes node image, it doesn't contain much we don't need
2021-04-10 07:48:34 +00:00
FROM ubuntu:focal-20210401
2020-09-27 13:00:33 +00:00
2021-07-21 17:54:27 +00:00
ARG BUILDKIT_VERSION = "v0.9.0"
2021-08-26 06:01:07 +00:00
ARG FUSE_OVERLAYFS_VERSION = "v1.7.1"
ARG CONTAINERD_FUSE_OVERLAYFS_VERSION = "1.0.3"
2021-09-10 17:35:34 +00:00
ARG CRIO_VERSION = "1.22"
2020-11-18 06:58:44 +00:00
2020-09-27 13:00:33 +00:00
# copy in static files (configs, scripts)
2021-06-22 21:49:53 +00:00
COPY deploy/kicbase/10-network-security.conf /etc/sysctl.d/10-network-security.conf
COPY deploy/kicbase/11-tcp-mtu-probing.conf /etc/sysctl.d/11-tcp-mtu-probing.conf
COPY deploy/kicbase/clean-install /usr/local/bin/clean-install
COPY deploy/kicbase/entrypoint /usr/local/bin/entrypoint
2021-06-29 22:57:49 +00:00
COPY --from= 0 /src/cmd/auto-pause/auto-pause /bin/auto-pause
2020-09-27 13:00:33 +00: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):
# - packages needed to run services (systemd)
# - packages needed for kubernetes components
# - packages needed by the container runtime
# - misc packages kind uses itself
2020-10-22 21:55:06 +00:00
# - packages that provide semi-core kubernetes functionality
2020-09-27 13:00:33 +00:00
# After installing packages we cleanup by:
# - removing unwanted systemd services
# - disabling kmsg in journald (these log entries would be confusing)
#
# Next we ensure the /etc/kubernetes/manifests directory exists. Normally
2021-02-09 16:49:00 +00:00
# a kubeadm debian / rpm package would ensure that this exists but we install
2020-09-27 13:00:33 +00:00
# freshly built binaries directly when we build the node image.
#
# 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.
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 \
conntrack iptables iproute2 ethtool socat util-linux mount ebtables udev kmod \
2020-10-22 21:55:06 +00:00
libseccomp2 pigz \
2020-09-27 13:00:33 +00:00
bash ca-certificates curl rsync \
2020-10-22 21:55:06 +00:00
nfs-common \
2021-05-12 01:49:37 +00:00
iputils-ping netcat-openbsd vim-tiny \
2020-09-27 13:00:33 +00: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/* \
&& echo "ReadKMsg=no" >> /etc/systemd/journald.conf \
&& ln -s " $( which systemd) " /sbin/init \
&& echo "Ensuring /etc/kubernetes/manifests" \
&& mkdir -p /etc/kubernetes/manifests \
&& echo "Adjusting systemd-tmpfiles timer" \
&& sed -i /usr/lib/systemd/system/systemd-tmpfiles-clean.timer -e 's#OnBootSec=.*#OnBootSec=1min#' \
2021-02-09 16:49:00 +00:00
&& echo "Disabling udev" \
&& systemctl disable udev.service \
2020-09-27 13:00:33 +00:00
&& echo "Modifying /etc/nsswitch.conf to prefer hosts" \
&& sed -i /etc/nsswitch.conf -re 's#^(hosts:\s*).*#\1dns files#'
# tell systemd that it is in docker (it will check for the container env)
2020-10-22 21:55:06 +00:00
# https://systemd.io/CONTAINER_INTERFACE/
2020-09-27 13:00:33 +00:00
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
# NOTE: this is *only* for documentation, the entrypoint is overridden later
ENTRYPOINT [ "/usr/local/bin/entrypoint" , "/sbin/init" ]
2019-12-23 06:19:52 +00:00
ARG COMMIT_SHA
2021-04-10 07:48:34 +00:00
# using base image created by kind https://github.com/kubernetes-sigs/kind/blob/b6bc1125/images/base/Dockerfile
# available as a docker image: docker.io/kindest/base:v20210402-3d9112b0
# which is an ubuntu 20.10 with an entry-point that helps running systemd
2020-02-03 23:31:52 +00:00
# could be changed to any debian that can run systemd
2019-12-23 07:39:44 +00:00
USER root
2020-08-31 18:00:06 +00:00
# install system requirements from the regular distro repositories
RUN clean-install \
2020-07-28 20:38:35 +00:00
lz4 \
gnupg \
sudo \
openssh-server \
dnsutils \
2020-03-24 00:41:06 +00:00
# libglib2.0-0 is required for conmon, which is required for podman
2021-08-26 06:01:07 +00:00
libglib2.0-0 \
# fuse3 is required for fuse-overlayfs
fuse3
2020-04-23 18:05:47 +00:00
2020-10-17 10:48:33 +00:00
# install docker
RUN sh -c "echo 'deb https://download.docker.com/linux/ubuntu focal stable' > /etc/apt/sources.list.d/docker.list" && \
curl -L https://download.docker.com/linux/ubuntu/gpg -o docker.key && \
apt-key add - < docker.key && \
clean-install docker-ce docker-ce-cli containerd.io
2021-08-26 06:01:07 +00:00
# install fuse-overlayfs (used by rootless; apt-get version is old)
RUN curl -sSL --retry 5 --output /usr/local/bin/fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/${ FUSE_OVERLAYFS_VERSION } /fuse-overlayfs-$( uname -m) \
&& chmod +x /usr/local/bin/fuse-overlayfs
# install containerd-fuse-overlayfs (used by rootless)
RUN export ARCH = $( dpkg --print-architecture | sed 's/ppc64el/ppc64le/' | sed 's/armhf/arm-v7/' ) \
&& echo "Installing containerd-fuse-overlayfs..." \
&& export CONTAINERD_FUSE_OVERLAYFS_BASE_URL = " https://github.com/containerd/fuse-overlayfs-snapshotter/releases/download/v ${ CONTAINERD_FUSE_OVERLAYFS_VERSION } " \
&& curl -sSL --retry 5 --output /tmp/containerd-fuse-overlayfs.tgz " ${ CONTAINERD_FUSE_OVERLAYFS_BASE_URL } /containerd-fuse-overlayfs- ${ CONTAINERD_FUSE_OVERLAYFS_VERSION } -linux- ${ ARCH } .tar.gz " \
&& tar -C /usr/local/bin -xzvf /tmp/containerd-fuse-overlayfs.tgz \
&& rm -rf /tmp/containerd-fuse-overlayfs.tgz
COPY deploy/kicbase/containerd-fuse-overlayfs.service /etc/systemd/system/containerd-fuse-overlayfs.service
2020-11-18 06:58:44 +00:00
# install buildkit
RUN export ARCH = $( dpkg --print-architecture | sed 's/ppc64el/ppc64le/' | sed 's/armhf/arm-v7/' ) \
&& echo "Installing buildkit ..." \
2021-08-03 18:47:38 +00:00
&& addgroup --system buildkit \
2020-11-18 06:58:44 +00:00
&& export BUILDKIT_BASE_URL = " https://github.com/moby/buildkit/releases/download/ ${ BUILDKIT_VERSION } " \
&& curl -sSL --retry 5 --output /tmp/buildkit.tgz " ${ BUILDKIT_BASE_URL } /buildkit- ${ BUILDKIT_VERSION } .linux- ${ ARCH } .tar.gz " \
&& tar -C /usr/local -xzvf /tmp/buildkit.tgz \
&& rm -rf /tmp/buildkit.tgz \
2021-08-31 21:47:07 +00:00
&& mkdir -p /usr/local/lib/systemd/system \
&& curl -L --retry 5 --output /usr/local/lib/systemd/system/buildkit.service " https://raw.githubusercontent.com/moby/buildkit/ ${ BUILDKIT_VERSION } /examples/systemd/buildkit.service " \
&& curl -L --retry 5 --output /usr/local/lib/systemd/system/buildkit.socket " https://raw.githubusercontent.com/moby/buildkit/ ${ BUILDKIT_VERSION } /examples/systemd/buildkit.socket " \
&& mkdir -p /etc/buildkit \
&& echo "[worker.oci]\n enabled = false\n[worker.containerd]\n enabled = true\n namespace = \"k8s.io\"" > /etc/buildkit/buildkitd.toml \
2020-11-18 06:58:44 +00:00
&& chmod 755 /usr/local/bin/buildctl \
&& chmod 755 /usr/local/bin/buildkit-runc \
2021-02-28 08:15:38 +00:00
&& chmod 755 /usr/local/bin/buildkit-qemu-* \
2021-08-31 21:47:07 +00:00
&& chmod 755 /usr/local/bin/buildkitd \
&& systemctl enable buildkit.socket
2020-11-18 06:58:44 +00:00
2020-07-30 22:11:30 +00:00
# Install cri-o/podman dependencies:
2020-11-07 11:52:43 +00:00
RUN sh -c "echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list" && \
2020-07-28 20:38:35 +00:00
curl -LO https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_20.04/Release.key && \
2020-08-31 18:00:06 +00:00
apt-key add - < Release.key && \
2021-02-09 21:38:57 +00:00
clean-install containers-common catatonit conmon containernetworking-plugins cri-tools podman-plugins crun
2020-07-30 22:11:30 +00:00
2021-09-07 22:53:29 +00:00
# install cri-o based on https://github.com/cri-o/cri-o/blob/release-1.22/README.md#installing-cri-o
2021-09-10 17:35:34 +00:00
RUN sh -c " echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/ ${ CRIO_VERSION } /xUbuntu_20.04/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o: ${ CRIO_VERSION } .list " && \
curl -LO https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/${ CRIO_VERSION } /xUbuntu_20.04/Release.key && \
apt-key add - < Release.key && \
clean-install cri-o cri-o-runc
2020-04-22 21:41:49 +00:00
2020-02-22 21:46:17 +00:00
# install podman
2020-10-24 08:43:05 +00:00
RUN sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list" && \
curl -LO https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_20.04/Release.key && \
apt-key add - < Release.key && \
clean-install podman && \
addgroup --system podman && \
mkdir -p /etc/systemd/system/podman.socket.d && \
printf "[Socket]\nSocketMode=0660\nSocketUser=root\nSocketGroup=podman\n" \
> /etc/systemd/system/podman.socket.d/override.conf && \
mkdir -p /etc/tmpfiles.d && \
echo "d /run/podman 0770 root podman" > /etc/tmpfiles.d/podman.conf && \
systemd-tmpfiles --create
2020-04-27 17:45:34 +00:00
2020-07-20 20:47:36 +00:00
# automount service
2021-06-22 21:49:53 +00:00
COPY deploy/kicbase/automount/minikube-automount /usr/sbin/minikube-automount
COPY deploy/kicbase/automount/minikube-automount.service /usr/lib/systemd/system/minikube-automount.service
2020-07-20 20:47:36 +00:00
RUN ln -fs /usr/lib/systemd/system/minikube-automount.service \
/etc/systemd/system/multi-user.target.wants/minikube-automount.service
2020-04-22 21:41:49 +00:00
2020-11-12 22:20:41 +00:00
# scheduled stop service
2021-06-22 21:49:53 +00:00
COPY deploy/kicbase/scheduled-stop/minikube-scheduled-stop /var/lib/minikube/scheduled-stop/minikube-scheduled-stop
COPY deploy/kicbase/scheduled-stop/minikube-scheduled-stop.service /usr/lib/systemd/system/minikube-scheduled-stop.service
2021-02-21 08:12:31 +00:00
RUN chmod +x /var/lib/minikube/scheduled-stop/minikube-scheduled-stop
2020-11-12 22:20:41 +00:00
2020-02-22 21:46:17 +00:00
# disable non-docker runtimes by default
2021-09-10 17:35:34 +00:00
RUN systemctl disable containerd && systemctl disable crio && rm /etc/crictl.yaml
2020-02-03 23:31:52 +00:00
# enable docker which is default
2020-10-24 08:43:05 +00:00
RUN systemctl enable docker.service && systemctl enable podman.socket
2020-01-24 02:24:51 +00:00
# making SSH work for docker container
2020-02-03 23:31:52 +00:00
# based on https://github.com/rastasheep/ubuntu-sshd/blob/master/18.04/Dockerfile
2020-01-24 02:24:51 +00:00
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
2020-06-12 19:20:03 +00:00
2020-08-18 23:50:33 +00:00
# minikube relies on /etc/hosts for control-plane discovery. This prevents nefarious DNS servers from breaking it.
RUN sed -ri 's/dns files/files dns/g' /etc/nsswitch.conf
2021-02-20 01:41:24 +00:00
# metacopy breaks crio on certain OS and isn't necessary for minikube
2021-02-20 02:53:20 +00:00
# https://github.com/kubernetes/minikube/issues/10520
2021-02-20 01:41:24 +00:00
RUN sed -ri 's/mountopt = "nodev,metacopy=on"/mountopt = "nodev"/g' /etc/containers/storage.conf
2020-01-24 02:24:51 +00:00
EXPOSE 22
2020-02-22 21:46:17 +00:00
# create docker user for minikube ssh. to match VM using "docker" as username
2020-02-03 23:31:52 +00:00
RUN adduser --ingroup docker --disabled-password --gecos '' docker
RUN adduser docker sudo
2021-08-03 16:39:55 +00:00
RUN adduser docker podman
RUN adduser docker buildkit
2020-02-03 23:31:52 +00:00
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
RUN mkdir /home/docker/.ssh
USER root
# kind base-image entry-point expects a "kind" folder for product_name,product_uuid
# https://github.com/kubernetes-sigs/kind/blob/master/images/base/files/usr/local/bin/entrypoint
RUN mkdir -p /kind
2020-02-22 21:46:17 +00:00
# Deleting leftovers
2020-08-31 18:00:06 +00:00
RUN rm -rf \
2020-08-21 21:56:28 +00:00
/usr/share/doc/* \
/usr/share/man/* \
2021-02-13 01:18:40 +00:00
/usr/share/local/*
2020-07-27 20:12:38 +00:00
RUN echo " kic! Build: ${ COMMIT_SHA } Time : $( date) " > "/kic.txt"