Skip to content

Instantly share code, notes, and snippets.

@OlegJakushkin
Last active December 1, 2020 14:14
Show Gist options
  • Save OlegJakushkin/1de0bf7afee6b9ac5bffd0ffa2585984 to your computer and use it in GitHub Desktop.
Save OlegJakushkin/1de0bf7afee6b9ac5bffd0ffa2585984 to your computer and use it in GitHub Desktop.
# docker build -t kubenode .
FROM ubuntu:20.04
RUN apt update \
&& apt install -yq curl software-properties-common ca-certificates openssh-client apt-transport-https \
wget curl iptables supervisor systemd
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 6A030B21BA07F4FB \
&& apt-get update
RUN add-apt-repository "deb [arch=amd64] https://apt.kubernetes.io/ kubernetes-xenial main" \
&& apt-get update
ENV DOCKER_CHANNEL=stable \
DOCKER_VERSION=19.03.11 \
DOCKER_COMPOSE_VERSION=1.26.0 \
DEBUG=false
# Docker installation
RUN set -eux; \
\
arch="$(uname --m)"; \
case "$arch" in \
# amd64
x86_64) dockerArch='x86_64' ;; \
# arm32v6
armhf) dockerArch='armel' ;; \
# arm32v7
armv7) dockerArch='armhf' ;; \
# arm64v8
aarch64) dockerArch='aarch64' ;; \
*) echo >&2 "error: unsupported architecture ($arch)"; exit 1 ;;\
esac; \
\
if ! wget -O docker.tgz "https://download.docker.com/linux/static/${DOCKER_CHANNEL}/${dockerArch}/docker-${DOCKER_VERSION}.tgz"; then \
echo >&2 "error: failed to download 'docker-${DOCKER_VERSION}' from '${DOCKER_CHANNEL}' for '${dockerArch}'"; \
exit 1; \
fi; \
\
tar --extract \
--file docker.tgz \
--strip-components 1 \
--directory /usr/local/bin/ \
; \
rm docker.tgz; \
\
dockerd --version; \
docker --version
RUN apt-get update \
&& apt-get install -yq htop git \
net-tools \
aptitude \
build-essential \
python3-setuptools \
python3-dev \
python3-pip \
software-properties-common \
ansible \
curl \
iptables \
iputils-ping \
sudo \
kubelet kubeadm kubectl
RUN git clone --recursive https://github.com/cruizba/ubuntu-dind \
&& cd ubuntu-dind \
&& cp ./modprobe /usr/local/bin/ \
&& cp ./startup.sh /usr/local/bin/ \
&& cp ./supervisor/* /etc/supervisor/conf.d/ \
&& mkdir /opt/bash-utils/ \
&& cp ./logger.sh /opt/bash-utils/logger.sh
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/modprobe
VOLUME /var/lib/docker
# Docker compose installation
RUN curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
RUN pip3 install "more-itertools<=5.0.0"
ENTRYPOINT ["startup.sh"]
CMD ["sh"]
from l3ns.ldc import DockerNode
from l3ns.base.network import Network
from l3ns import defaults
defaults.network = Network('32.0.0.0/8')
n1 = DockerNode('master', image='ubuntu:bionic', command='tail -f /dev/null', tty=True, stdin_open=True)
n1 = DockerNode('worker1', image='ubuntu:bionic', command='tail -f /dev/null', tty=True, stdin_open=True)
n1 = DockerNode('worker2', image='ubuntu:bionic', command='tail -f /dev/null', tty=True, stdin_open=True)
n1.connect_to(n2)
n1.connect_to_internet = True
with defaults.network:
ret = n1.exec_run('ping -c 5 8.8.8.8') # it still will take a while
print(ret.exit_code)
print(ret.output)
# for infinite commands:
ret = n1.exec_run('ping 1.1.1.1', stream=True)
print(ret.exit_code) # None, command is still running
for i, line in enumerate(ret.output):
print(line)
if i >= 5:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment