Last active
December 16, 2020 10:14
-
-
Save OlegJakushkin/a4ca3d54f37ea41bc9c14650fe3003b5 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 | |
## kubenode software base | |
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" | |
### SSH | |
RUN useradd --create-home --no-log-init --shell /bin/bash -g root vagrant && \ | |
usermod -aG sudo vagrant && \ | |
usermod -aG users vagrant && \ | |
echo "vagrant:vagrant" | chpasswd | |
RUN apt update && apt --no-install-recommends install -y plink openssh-server ssh && \ | |
mkdir /var/run/sshd && \ | |
sed -ri 's/^#?PermitRootLogn\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config && \ | |
sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \ | |
echo "\nAllowGroups root" >> /etc/ssh/sshd_config && \ | |
mkdir /root/.ssh && \ | |
mkdir /home/vagrant/.ssh | |
EXPOSE 22 | |
ENTRYPOINT ["startup.sh"] | |
CMD ["/bin/bash"] |
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('43.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) | |
#worker1.connect_to(master) | |
#worker2.connect_to(master) | |
master.connect_to_internet = True | |
worker1.connect_to_internet = True | |
worker2.connect_to_internet = True | |
def save_file_on_a_node(node_ctx, str, file_path): | |
ret = node_ctx.exec_run('touch ' + file_path) | |
print(ret.exit_code) | |
print(ret.output) | |
ret = node_ctx.exec_run("""/bin/bash -c "cat <<EOT >> """+file_path+""" | |
""" + str + | |
""" | |
EOT" | |
""") | |
print(ret.exit_code) | |
print(ret.output.decode('ascii')) | |
return ret | |
def save_file_on_all_nodes(str, file_path): | |
save_file_on_a_node(master, str, file_path) | |
save_file_on_a_node(worker1, str, file_path) | |
save_file_on_a_node(worker2, str, file_path) | |
def run_on_a_node(node_ctx, cmd): | |
print("on "+node_ctx.name+" running: " + cmd ) | |
ret = node_ctx.exec_run(cmd) | |
#print(ret.exit_code) | |
#print(ret.output.decode('ascii')) | |
return ret | |
def run_on_all_nodes(str): | |
run_on_a_node(master, str) | |
run_on_a_node(worker1, str) | |
run_on_a_node(worker2, str) | |
with defaults.network: | |
hosts = """[masters] | |
master ansible_host="""+str(master.get_ip())+""" ansible_user=vagrant | |
[workers] | |
worker1 ansible_host="""+str(worker1.get_ip())+""" ansible_user=vagrant | |
worker2 ansible_host="""+str(worker2.get_ip())+""" ansible_user=vagrant | |
[all:vars] | |
ansible_python_interpreter=/usr/bin/python3 | |
ansible_connection=ssh | |
ansible_user=vagrant | |
ansible_ssh_pass=vagrant | |
""" | |
run_on_all_nodes( """/bin/bash -c "/usr/sbin/sshd -D" """) ## Here wa log onto nodes directly! | |
print("started SSH deamons on all nodes") | |
run_on_a_node(master, """/bin/bash -c "plink vagrant@"""+ str(worker1.get_ip())+ """ -pw vagrant ls" """) | |
print("press enter to stop simulation!") | |
input1 = input() | |
exit() |
Author
OlegJakushkin
commented
Dec 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment