Skip to content

Commit

Permalink
Add k8s-node v1.21 image.
Browse files Browse the repository at this point in the history
Signed-off-by: Cesar Talledo <[email protected]>
  • Loading branch information
ctalledo committed May 18, 2022
1 parent d87306e commit f870cf0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
5 changes: 2 additions & 3 deletions k8s-node-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# $ docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/nestybox/k8s-node-test:v1.20.2 --push .
#

FROM ghcr.io/nestybox/k8s-node:v1.20.2
FROM ghcr.io/nestybox/k8s-node:v1.21.12

ARG k8s_version=v1.20.2
ARG k8s_version=v1.21.12

# Debug/Testing utilities
RUN apt-get update && apt-get install --no-install-recommends -y \
Expand All @@ -35,4 +35,3 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
tcpdump \
bridge-utils \
&& rm -rf /var/lib/apt/lists/*

92 changes: 92 additions & 0 deletions k8s-node/1.21/Dockerfile
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
3 changes: 3 additions & 0 deletions k8s-node/1.21/daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
39 changes: 39 additions & 0 deletions k8s-node/1.21/kube-pull.sh
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

0 comments on commit f870cf0

Please sign in to comment.