Skip to content

Commit fe02be1

Browse files
authored
Merge pull request kubernetes#87931 from dims/ability-to-use-containerd-as-runtime
Ability to use containerd as runtime in kube-up (on Ubuntu)
2 parents ac97b2d + da024f9 commit fe02be1

File tree

5 files changed

+94
-7
lines changed

5 files changed

+94
-7
lines changed

cluster/gce/config-default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ if [[ "${CONTAINER_RUNTIME}" == "containerd" ]]; then
101101
LOAD_IMAGE_COMMAND=${KUBE_LOAD_IMAGE_COMMAND:-ctr -n=k8s.io images import}
102102
fi
103103

104+
# Ability to inject custom versions (Ubuntu OS images ONLY)
105+
# if KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION or KUBE_UBUNTU_INSTALL_RUNC_VERSION
106+
# is set to empty then we do not override the version(s) and just
107+
# use whatever is in the default installation of containerd package
108+
UBUNTU_INSTALL_CONTAINERD_VERSION=${KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION:-}
109+
UBUNTU_INSTALL_RUNC_VERSION=${KUBE_UBUNTU_INSTALL_RUNC_VERSION:-}
110+
104111
# MASTER_EXTRA_METADATA is the extra instance metadata on master instance separated by commas.
105112
MASTER_EXTRA_METADATA=${KUBE_MASTER_EXTRA_METADATA:-${KUBE_EXTRA_METADATA:-}}
106113
# MASTER_EXTRA_METADATA is the extra instance metadata on node instance separated by commas.

cluster/gce/config-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ if [[ "${CONTAINER_RUNTIME}" == "containerd" ]]; then
107107
LOAD_IMAGE_COMMAND=${KUBE_LOAD_IMAGE_COMMAND:-ctr -n=k8s.io images import}
108108
fi
109109

110+
# Ability to inject custom versions (Ubuntu OS images ONLY)
111+
# if KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION or KUBE_UBUNTU_INSTALL_RUNC_VERSION
112+
# is set to empty then we do not override the version(s) and just
113+
# use whatever is in the default installation of containerd package
114+
UBUNTU_INSTALL_CONTAINERD_VERSION=${KUBE_UBUNTU_INSTALL_CONTAINERD_VERSION:-}
115+
UBUNTU_INSTALL_RUNC_VERSION=${KUBE_UBUNTU_INSTALL_RUNC_VERSION:-}
116+
110117
# MASTER_EXTRA_METADATA is the extra instance metadata on master instance separated by commas.
111118
MASTER_EXTRA_METADATA=${KUBE_MASTER_EXTRA_METADATA:-${KUBE_EXTRA_METADATA:-}}
112119
# MASTER_EXTRA_METADATA is the extra instance metadata on node instance separated by commas.

cluster/gce/gci/configure-helper.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,6 @@ EOF
26682668
cni_template_path=""
26692669
fi
26702670
fi
2671-
# Reuse docker group for containerd.
2672-
local containerd_gid="$(cat /etc/group | grep ^docker: | cut -d: -f 3)"
26732671
cat > "${config_path}" <<EOF
26742672
# Kubernetes doesn't use containerd restart manager.
26752673
disabled_plugins = ["restart"]
@@ -2678,9 +2676,6 @@ oom_score = -999
26782676
[debug]
26792677
level = "${CONTAINERD_LOG_LEVEL:-"info"}"
26802678
2681-
[grpc]
2682-
gid = ${containerd_gid}
2683-
26842679
[plugins.cri]
26852680
stream_server_address = "127.0.0.1"
26862681
max_container_log_line_size = ${CONTAINERD_MAX_CONTAINER_LOG_LINE:-262144}
@@ -2691,6 +2686,16 @@ oom_score = -999
26912686
[plugins.cri.registry.mirrors."docker.io"]
26922687
endpoint = ["https://mirror.gcr.io","https://registry-1.docker.io"]
26932688
EOF
2689+
2690+
# Reuse docker group for containerd.
2691+
local containerd_gid="$(cat /etc/group | grep ^docker: | cut -d: -f 3)"
2692+
if [[ ! -z "${containerd_gid:-}" ]]; then
2693+
cat >> "${config_path}" <<EOF
2694+
# reuse id of the docker group
2695+
[grpc]
2696+
gid = ${containerd_gid}
2697+
EOF
2698+
fi
26942699
chmod 644 "${config_path}"
26952700

26962701
echo "Restart containerd to load the config change"

cluster/gce/gci/configure.sh

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function load-docker-images {
407407
function install-docker {
408408
# bailout if we are not on ubuntu
409409
if ! command -v apt-get >/dev/null 2>&1; then
410-
echo "Unable to install automatically install docker. Bailing out..."
410+
echo "Unable to automatically install docker. Bailing out..."
411411
return
412412
fi
413413
# Install Docker deps, some of these are already installed in the image but
@@ -436,6 +436,55 @@ function install-docker {
436436
rm -rf /var/lib/apt/lists/*
437437
}
438438

439+
# If we are on ubuntu we can try to install containerd
440+
function install-containerd-ubuntu {
441+
# bailout if we are not on ubuntu
442+
if [[ -z "$(command -v lsb_release)" || $(lsb_release -si) != "Ubuntu" ]]; then
443+
echo "Unable to automatically install containerd in non-ubuntu image. Bailing out..."
444+
exit 2
445+
fi
446+
447+
if [[ $(dpkg --print-architecture) != "amd64" ]]; then
448+
echo "Unable to automatically install containerd in non-amd64 image. Bailing out..."
449+
exit 2
450+
fi
451+
452+
# Install dependencies, some of these are already installed in the image but
453+
# that's fine since they won't re-install and we can reuse the code below
454+
# for another image someday.
455+
apt-get update
456+
apt-get install -y --no-install-recommends \
457+
apt-transport-https \
458+
ca-certificates \
459+
socat \
460+
curl \
461+
gnupg2 \
462+
software-properties-common \
463+
lsb-release
464+
465+
# Add the Docker apt-repository (as we install containerd from there)
466+
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg \
467+
| apt-key add -
468+
add-apt-repository \
469+
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
470+
$(lsb_release -cs) stable"
471+
472+
# Install containerd from Docker repo
473+
apt-get update && \
474+
apt-get install -y --no-install-recommends containerd
475+
rm -rf /var/lib/apt/lists/*
476+
477+
# Override to latest versions of containerd and runc
478+
systemctl stop containerd
479+
if [[ ! -z "${UBUNTU_INSTALL_CONTAINERD_VERSION:-}" ]]; then
480+
curl -fsSL "https://github.com/containerd/containerd/releases/download/${UBUNTU_INSTALL_CONTAINERD_VERSION}/containerd-${UBUNTU_INSTALL_CONTAINERD_VERSION:1}.linux-amd64.tar.gz" | tar --overwrite -xzv -C /usr/
481+
fi
482+
if [[ ! -z "${UBUNTU_INSTALL_RUNC_VERSION:-}" ]]; then
483+
curl -fsSL "https://github.com/opencontainers/runc/releases/download/${UBUNTU_INSTALL_RUNC_VERSION}/runc.amd64" --output /usr/sbin/runc && chmod 755 /usr/sbin/runc
484+
fi
485+
sudo systemctl start containerd
486+
}
487+
439488
function ensure-container-runtime {
440489
container_runtime="${CONTAINER_RUNTIME:-docker}"
441490
if [[ "${container_runtime}" == "docker" ]]; then
@@ -448,11 +497,28 @@ function ensure-container-runtime {
448497
fi
449498
docker version
450499
elif [[ "${container_runtime}" == "containerd" ]]; then
500+
# Install containerd/runc if requested
501+
if [[ ! -z "${UBUNTU_INSTALL_CONTAINERD_VERSION:-}" || ! -z "${UBUNTU_INSTALL_RUNC_VERSION}" ]]; then
502+
install-containerd-ubuntu
503+
fi
504+
# Verify presence and print versions of ctr, containerd, runc
451505
if ! command -v ctr >/dev/null 2>&1; then
452506
echo "ERROR ctr not found. Aborting."
453507
exit 2
454508
fi
455-
ctr version
509+
ctr --version
510+
511+
if ! command -v containerd >/dev/null 2>&1; then
512+
echo "ERROR containerd not found. Aborting."
513+
exit 2
514+
fi
515+
containerd --version
516+
517+
if ! command -v runc >/dev/null 2>&1; then
518+
echo "ERROR runc not found. Aborting."
519+
exit 2
520+
fi
521+
runc --version
456522
fi
457523
}
458524

cluster/gce/util.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,8 @@ DISABLE_PROMETHEUS_TO_SD_IN_DS: $(yaml-quote ${DISABLE_PROMETHEUS_TO_SD_IN_DS:-f
12241224
CONTAINER_RUNTIME: $(yaml-quote ${CONTAINER_RUNTIME:-})
12251225
CONTAINER_RUNTIME_ENDPOINT: $(yaml-quote ${CONTAINER_RUNTIME_ENDPOINT:-})
12261226
CONTAINER_RUNTIME_NAME: $(yaml-quote ${CONTAINER_RUNTIME_NAME:-})
1227+
UBUNTU_INSTALL_CONTAINERD_VERSION: $(yaml-quote ${UBUNTU_INSTALL_CONTAINERD_VERSION:-})
1228+
UBUNTU_INSTALL_RUNC_VERSION: $(yaml-quote ${UBUNTU_INSTALL_RUNC_VERSION:-})
12271229
NODE_LOCAL_SSDS_EXT: $(yaml-quote ${NODE_LOCAL_SSDS_EXT:-})
12281230
LOAD_IMAGE_COMMAND: $(yaml-quote ${LOAD_IMAGE_COMMAND:-})
12291231
ZONE: $(yaml-quote ${ZONE})

0 commit comments

Comments
 (0)