-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Cesar Talledo <[email protected]>
- Loading branch information
Showing
4 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Sample Kubernetes (K8s) node system container image. | ||
# | ||
# Containers deployed with this image acts as K8s nodes. | ||
# | ||
# The image creates a container that includes systemd, kubeadm, docker, and all | ||
# k8s control plane pod images (apiserver, kubeproxy, etc.). | ||
# | ||
# You must deploy the container with the Sysbox container runtime (see below). | ||
# | ||
# NOTE: BUILDING THIS IMAGE REQUIRES CONFIGURING SYSBOX-RUNC AS DOCKER'S DEFAULT | ||
# RUNTIME DURING THE BUILD. | ||
# | ||
# $ sudo more /etc/docker/daemon.json | ||
#{ | ||
# "default-runtime": "sysbox-runc", | ||
# "runtimes": { | ||
# "sysbox-runc": { | ||
# "path": "/usr/bin/sysbox-runc" | ||
# } | ||
# } | ||
#} | ||
# | ||
# $ sudo systemctl restart docker | ||
# $ docker build -t nestybox/k8s-node:<k8s_version> . | ||
# | ||
# E.g., | ||
# | ||
# $ docker build -t nestybox/k8s-node:v1.21.12 . | ||
# | ||
# Once the build completes, you can revert the default runtime config if you wish. | ||
# | ||
# Deploy k8s-node containers with: | ||
# | ||
# $ docker run --runtime=sysbox-runc --rm -d --name k8s-master nestybox/k8s-node:v1.21.12 | ||
# $ docker run --runtime=sysbox-runc --rm -d --name k8s-worker-0 nestybox/k8s-node:v1.21.12 | ||
# $ docker run --runtime=sysbox-runc --rm -d --name k8s-worker-1 nestybox/k8s-node:v1.21.12 | ||
# ... | ||
# | ||
# Then run 'kubeadm init' in them just as you would on a physical host or VM. | ||
|
||
FROM nestybox/ubuntu-focal-systemd:latest | ||
|
||
ARG k8s_version=v1.21.12 | ||
|
||
# Install Docker. | ||
RUN apt-get update && apt-get install --no-install-recommends -y \ | ||
apt-transport-https \ | ||
ca-certificates \ | ||
curl \ | ||
gnupg-agent \ | ||
software-properties-common \ | ||
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \ | ||
&& apt-key fingerprint 0EBFCD88 \ | ||
&& add-apt-repository \ | ||
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | ||
$(lsb_release -cs) \ | ||
stable" \ | ||
&& apt-get update \ | ||
&& apt-get install --no-install-recommends -y docker-ce docker-ce-cli containerd.io \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
# Add user "admin" to the Docker group \ | ||
&& usermod -a -G docker admin | ||
|
||
|
||
# Install Kubeadm. | ||
# | ||
# Note: we use kubeadm for Ubuntu Xenial because a version for Bionic is not available; | ||
# see https://packages.cloud.google.com/apt/dists/ | ||
RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add \ | ||
&& apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" \ | ||
&& apt-get update && apt-get install --no-install-recommends -y \ | ||
kubeadm="${k8s_version#v}"-00 \ | ||
kubelet="${k8s_version#v}"-00 \ | ||
kubectl="${k8s_version#v}"-00 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Preload k8s control plane container images into the sys container image. | ||
COPY kube-pull.sh /usr/bin/ | ||
RUN chmod +x /usr/bin/kube-pull.sh && kube-pull.sh $k8s_version && rm /usr/bin/kube-pull.sh | ||
|
||
# Docker daemon config. | ||
COPY daemon.json /etc/docker/ | ||
|
||
# bash completion | ||
RUN apt-get update \ | ||
&& mkdir -p /etc/bash_completion.d \ | ||
&& apt-get install bash-completion \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& echo "source /etc/profile.d/bash_completion.sh" >> /root/.bashrc \ | ||
&& echo "source <(kubectl completion bash)" >> /root/.bashrc \ | ||
&& echo "source /etc/profile.d/bash_completion.sh" >> /home/admin/.bashrc \ | ||
&& echo "source <(kubectl completion bash)" >> /home/admin/.bashrc |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"exec-opts": ["native.cgroupdriver=systemd"] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Runs inside the K8s node system container; requests kubeadm to pull K8s | ||
# control-plane components. | ||
# | ||
|
||
usage() { | ||
echo "\nUsage: $0 <k8s-version>\n" | ||
echo "E.g., $0 v1.18.2" | ||
} | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Invalid number of arguments. Expect 1, got $#". | ||
usage | ||
exit 1 | ||
fi | ||
|
||
k8s_version=$1 | ||
|
||
# start dockerd | ||
dockerd > /var/log/dockerd.log 2>&1 & | ||
dockerd_pid=$! | ||
sleep 2 | ||
|
||
# pull inner images | ||
kubeadm config images pull --kubernetes-version=$k8s_version | ||
# flannel cni | ||
docker image pull quay.io/coreos/flannel:v0.12.0-amd64 | ||
# weaveNet cni | ||
docker image pull docker.io/weaveworks/weave-kube:2.8.1 | ||
docker image pull docker.io/weaveworks/weave-npc:2.8.1 | ||
# calico cni | ||
docker image pull quay.io/tigera/operator:v1.17.2 | ||
|
||
# stop dockerd (remove the .pid file as otherwise it may prevent | ||
# dockerd from launching correctly inside the sys container) | ||
kill $dockerd_pid | ||
rm -f /var/run/docker.pid |