kubernetes: Kubeadm inside docker container fails

When trying to install Kubeadm inside Ubuntu 16.04 docker container it fails.

BUG REPORT

Kubernetes version (use kubectl version): latest

Environment: Ubuntu 16.04 Docker container

What happened: When trying to install Kubeadm inside Ubuntu 16.04 docker container it fails. My Idea was to use one docker container as master “node” and a second container as a worker “node” (kubernetes in docker) Is this a systemd issue? (something I came across when “googling” for answers)

Inside Ubuntu 16.04 docker image I install with : apt-get install -y kubeadm

setup log:

...
...
...
all: Setting up socat (1.7.3.1-1) ...
    all: Setting up kubelet (1.4.3-00) ...
    all: /var/lib/dpkg/info/kubelet.postinst: 38: /var/lib/dpkg/info/kubelet.postinst: [[: not found
    all: Setting up kubectl (1.4.3-00) ...
    all: Setting up kubeadm (1.5.0-alpha.0-1534-gcf7301f-00) ...
    all: Failed to connect to bus: No such file or directory
    **all: dpkg: error processing package kubeadm (--configure):**
    all: subprocess installed post-installation script returned error exit status 1
    all: Setting up netcat-traditional (1.10-41) ...
    all: update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in auto mode
    all: Setting up netcat (1.10-41) ...
    all: Setting up patch (2.7.5-1) ...
    all: Setting up rename (0.20-4) ...
    all: update-alternatives: using /usr/bin/file-rename to provide /usr/bin/rename (rename) in auto mode
    all: Setting up tcpd (7.6.q-25) ...
    all: Setting up ubuntu-fan (0.9.1) ...
    all: invoke-rc.d: could not determine current runlevel
    all: invoke-rc.d: policy-rc.d denied execution of start.
    all: Setting up xz-utils (5.1.1alpha+20120614-2ubuntu2) ...
    all: update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
    all: Setting up python3 (3.5.1-3) ...
    all: running python rtupdate hooks for python3.5...
    all: running python post-rtupdate hooks for python3.5...
    all: Setting up apparmor (2.10.95-0ubuntu2.2) ...
    all: update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
    all: Setting up dh-python (2.20151103ubuntu1.1) ...
    all: Processing triggers for libc-bin (2.23-0ubuntu4) ...
    all: Processing triggers for systemd (229-4ubuntu11) ...
    all: Processing triggers for initramfs-tools (0.122ubuntu8.5) ...
    all: Processing triggers for dbus (1.10.6-1ubuntu3) ...
    all: Errors were encountered while processing:
    all: kubeadm
    all: E: Sub-process /usr/bin/dpkg returned an error code (1)
==> all: Killing the container: 93babb5045461c343a803109ba683a2acf68f1f453447a336b09171a1b190f38
Build 'all' errored: Script exited with non-zero exit status: 100

==> Some builds didn't complete successfully and had errors:
--> all: Script exited with non-zero exit status: 100

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 16 (11 by maintainers)

Most upvoted comments

There are two main issues regarding to installation kubeadm in Docker container. First is systemd running in container. Second is installation docker inside container. Successfully the problems were fixed. Here is the Dockerfile which must be used to prepare Ubuntu image

FROM ubuntu
ENV container docker
RUN apt-get -y update

RUN apt-get update -qq && apt-get install -qqy \
    apt-transport-https \
    ca-certificates \
    curl \
    lxc \
    vim \
    iptables

RUN curl -sSL https://get.docker.com/ | sh

RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
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/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;

VOLUME /sys/fs/cgroup
VOLUME /var/run/docker.sock
CMD /sbin/init

I use this command to build the image in the directory containing the Dockerfile

docker build -t kubeadm_docker .

Now you can run prepared image and finish kubeadm installation. Use the following command to run kubeadm_docker image:

docker run -it -e "container=docker" --privileged=true -d --security-opt seccomp:unconfined --cap-add=SYS_ADMIN -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /var/run/docker.sock:/var/run/docker.sock  kubeadm_docker /sbin/init

Find running container ID

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
7dd73057620d        kubeadm_docker      "/sbin/init"        About an hour ago   Up About an hour                        furious_fermi

Now you can open container console:

docker exec -it 7dd73057620d /bin/bash

This is your script (with small modifications) to install kubeadm

echo "Updating Ubuntu..."
apt-get update -y
apt-get upgrade -y

systemctl start docker

echo "Install os requirements"
apt-get install -y \
  curl \
  apt-transport-https \
  dialog \
  python \
  daemon

echo "Add Kubernetes repo..."
sh -c 'curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -'
sh -c 'echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list'
apt-get update -y

echo "Installing Kubernetes requirements..."
apt-get install -y \
  kubelet

# This is temporary fix until new version will be released
sed -i 38,40d /var/lib/dpkg/info/kubelet.postinst

apt-get install -y \
  kubernetes-cni \
  kubectl \
  kubeadm

And finally you can execute

# kubeadm init

Everything works the same like on local machine. Good luck 😃