Created
December 8, 2020 14:13
-
-
Save OlegJakushkin/fc1ca3ef44516abbddb13975e5ec4a27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-ubuntu-18-04 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
from l3ns.ldc import DockerNode | |
from l3ns.base.network import Network | |
from l3ns import defaults | |
defaults.network = Network('35.0.0.0/8') | |
master = DockerNode('master', image='kubenode', command='tail -f /dev/null', tty=True, stdin_open=True) | |
worker1 = DockerNode('worker1', image='kubenode', command='tail -f /dev/null', tty=True, stdin_open=True) | |
worker2 = DockerNode('worker2', image='kubenode', command='tail -f /dev/null', tty=True, stdin_open=True) | |
master.connect_to(worker1) | |
master.connect_to(worker2) | |
master.connect_to_internet = True | |
worker1.connect_to_internet = True | |
worker2.connect_to_internet = True | |
with defaults.network: | |
hosts = """ | |
[masters] | |
master ansible_host="""+str(master.get_ip())+""" ansible_user=root | |
[workers] | |
worker1 ansible_host="""+str(worker1.get_ip())+""" ansible_user=root | |
worker2 ansible_host="""+str(worker2.get_ip())+""" ansible_user=root | |
[all:vars] | |
ansible_python_interpreter=/usr/bin/python3 | |
""" | |
hosts_f = open("hosts", "w") | |
hosts_f.write(hosts) | |
hosts_f.close() | |
data = open('hosts', 'rb').read() | |
ret = master.exec_run('touch /tmp/hosts') | |
print(ret.exit_code) | |
print(ret.output) | |
ret = master.exec_run("""/bin/bash -c "cat <<EOT >> /tmp/hosts | |
""" + hosts + | |
""" | |
EOT" | |
""") | |
print(ret.exit_code) | |
print(ret.output) | |
ret = master.exec_run('cat /tmp/hosts') # it still will take a while | |
print(ret.exit_code) | |
print(ret.output) | |
ret = worker2.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 = worker1.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