Skip to content

Instantly share code, notes, and snippets.

@lenartj
Last active January 27, 2019 05:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save lenartj/0b264cb70e6cb50dfdef37084f892554 to your computer and use it in GitHub Desktop.
Save lenartj/0b264cb70e6cb50dfdef37084f892554 to your computer and use it in GitHub Desktop.
Kubernetes with kubeadm on Ubuntu Trusty (14.04) hack
#!/bin/bash
#
# This script is meant to be run on Ubuntu Trusty (14.04) as root
#
# It is expected that you are following the guide at:
# https://kubernetes.io/docs/setup/independent/install-kubeadm/
# https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
#
# Particularly you will need to have (BEFORE you start):
# - binutils, ebtables, socat installed
# - docker installed and running
# - kubernetes-cni and kubectl installed
#
# It will create a directory in /tmp with the following artifacts in it:
# - nsenter binary (to be copied to /usr/local/bin)
# - kubelet-patched.deb (to be installed)
# - kubeadm-patched.deb (to be installed)
# (No changes on your system other than that directory)
#
# After you have done those steps do:
# - kubeadm init
# - start kubelet (from another shell, while kubeadm is waiting for the control plane)
# - continue with "(3/4) Installing a pod network"
#
set -e
set -x
getpkg()
{
local path=`apt-cache show "$1" | grep Filename | sort | tail -n1 | cut -d ' ' -f2`
wget "https://packages.cloud.google.com/apt/$path"
}
unpkg()
{
ar x "$1"
gzip -dv control.tar.gz
unxz -v data.tar.xz
}
repkg()
{
gzip -v control.tar
xz -v0 data.tar
ar cr "$1" debian-binary control.tar.gz data.tar.xz
}
make_kubelet()
{
rm -rf kubelet
mkdir kubelet
cd kubelet
getpkg kubelet
unpkg kubelet*deb
# replace maintainer scripts
tar xvf control.tar ./control
sed 's/init-system-helpers (>= 1.18~)/init-system-helpers (>= 1.14~)/' -i control
cat >prerm <<EOF
#!/bin/sh
stop kubelet || true
exit 0
EOF
cat >postinst <<EOF
#!/bin/sh
exit 0
EOF
cp postinst postrm
tar --update -v -f control.tar ./control ./prerm ./postinst ./postrm
# remove systemd unit
tar --delete -v -f data.tar ./lib/systemd
repkg ../kubelet-patched.deb
cd ..
rm -rf kubelet
}
make_kubeadm()
{
mkdir kubeadm
cd kubeadm
getpkg kubeadm
unpkg kubeadm*deb
# replace maintainer scripts
echo "/etc/init/kubelet.conf" >conffiles
cat >postinst <<EOF
#!/bin/sh
[ "$1" = configure ] && restart kubelet
exit 0
EOF
tar --update -v -f control.tar ./conffiles ./postinst
# replace systemd unit
mkdir -p etc/init
cat >etc/init/kubelet.conf <<EOF
description "Kubelet"
start on (docker)
stop on runlevel [!2345]
limit nproc unlimited unlimited
respawn
kill timeout 30
script
KUBELET_KUBECONFIG_ARGS="--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
KUBELET_SYSTEM_PODS_ARGS="--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
KUBELET_NETWORK_ARGS="--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
KUBELET_DNS_ARGS="--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
KUBELET_AUTHZ_ARGS="--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
exec /usr/bin/kubelet \$KUBELET_KUBECONFIG_ARGS \$KUBELET_SYSTEM_PODS_ARGS \$KUBELET_NETWORK_ARGS \$KUBELET_DNS_ARGS \$KUBELET_AUTHZ_ARGS \$KUBELET_EXTRA_ARGS
end script
EOF
tar --delete -v -f data.tar ./etc/systemd
tar --add-file=./etc -r -v -f data.tar
repkg ../kubeadm-patched.deb
cd ..
rm -rf kubeadm
}
make_nsenter()
{
cat <<EOF | docker run -i --rm -v "`pwd`:/tmp" ubuntu:14.04
apt-get update
apt-get install -y git bison
apt-get build-dep -y util-linux
cd /tmp
git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
cd util-linux
./autogen.sh
./configure --without-python --disable-all-programs --enable-nsenter
make nsenter
EOF
cp -v util-linux/nsenter .
rm -rf util-linux
}
tmp=`mktemp -d`
cd "$tmp"
make_kubelet
make_kubeadm
make_nsenter
cat <<EOF
All done!
# cp -v $tmp/nsenter /usr/local/bin
# dpkg -i $tmp/*-patched.deb
EOF
@sjain2682
Copy link

sjain2682 commented Mar 23, 2018

script is failing at make_nsenter function with error message saying that "E: Unable to find a source package for util-linux
Cloning into 'util-linux'.."

After modifying this function as mentioned below, it worked:

make_nsenter()
{
cat <<EOF | docker run -i --rm -v "pwd:/tmp" ubuntu:14.04
apt-get update
apt-get install -y git bison
apt-get build-dep -y util-linux
apt-get install -y autopoint
apt-get install -y autoconf
apt-get install -y libtool
apt-get install -y gettext
apt-get install -y pkg-config
apt-get install -y make
cd /tmp
git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
cd util-linux
./autogen.sh
./configure --without-python --disable-all-programs --enable-nsenter
make nsenter
EOF
cp -v util-linux/nsenter .
rm -rf util-linux
}

@davidcsi
Copy link

davidcsi commented Apr 9, 2018

Hello, At installation (using the make_nsenter on the comments) i'm getting:

+ docker run -i --rm -v pwd:/tmp ubuntu:14.04
FATA[0001] Error response from daemon: cannot bind mount volume: pwd volume paths must be absolute.

The script as provided fails with:

Processing triggers for ureadahead (0.100.0-16) ...
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to find a source package for util-linux
Cloning into 'util-linux'...

You must have autopoint installed to generate the util-linux build system.
The autopoint command is part of the GNU gettext package.


You must have autoconf installed to generate the util-linux build system.


You must have autoheader installed to generate the util-linux build system.
The autoheader command is part of the GNU autoconf package.


You must have libtool-2 installed to generate the util-linux build system.


You must have automake installed to generate the util-linux build system.

/bin/bash: line 8: ./configure: No such file or directory
/bin/bash: line 9: make: command not found
root@david-ubuntu-laptop:~#

And i think it's all installed

Thanks!

@YonatanKiron
Copy link

@davidcsi I think you missed the `` around the pwd command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment