From 117fd4ab9fc7fb5ea0242c7ddd209cd609e19777 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Wed, 21 Aug 2024 18:18:14 +0200 Subject: [PATCH] Configure docker proxy URL for K3s-based installation to overcome docker pull rate limit Change-Id: I94dde54e4f124369daaf40ff6863b77e2fd25d23 Signed-off-by: garciadeblas --- installers/full_install_osm.sh | 1 + installers/install_k3s_cluster.sh | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 1b183349..6cde383f 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -429,6 +429,7 @@ function install_k8s_cluster() { FATAL_TRACK k8scluster "install_cluster_addons.sh failed for kubeadm cluster" elif [ "${K8S_CLUSTER_ENGINE}" == "k3s" ]; then K3S_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -D ${OSM_DEVOPS} ${DEBUG_INSTALL}" + [ -n "${DOCKER_PROXY_URL}" ] && K3S_INSTALL_OPTS="${K3S_INSTALL_OPTS} -p ${DOCKER_PROXY_URL}" # The K3s installation script will automatically take the HTTP_PROXY, HTTPS_PROXY and NO_PROXY, # as well as the CONTAINERD_HTTP_PROXY, CONTAINERD_HTTPS_PROXY and CONTAINERD_NO_PROXY variables # from the shell, if they are present, and write them to the environment file of k3s systemd service, diff --git a/installers/install_k3s_cluster.sh b/installers/install_k3s_cluster.sh index a604ef16..fea91f41 100755 --- a/installers/install_k3s_cluster.sh +++ b/installers/install_k3s_cluster.sh @@ -18,6 +18,19 @@ set +eux # K3s releases: https://github.com/k3s-io/k3s/releases/ K8S_VERSION="v1.29.3+k3s1" +# configure registry +function configure_registry() { + if [ -n "${DOCKER_PROXY_URL}" ]; then + echo "Configuring docker proxy URL in /etc/rancher/k3s/registries.yaml" + cat << EOF | sudo tee /etc/rancher/k3s/registries.yaml > /dev/null +mirrors: + docker.io: + endpoint: + - "${DOCKER_PROXY_URL}" +EOF + fi +} + # installs k3s function install_k3s() { [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function @@ -138,7 +151,7 @@ function save_kubeconfig() { } # main -while getopts ":D:i:-: " o; do +while getopts ":D:i:p:-: " o; do case "${o}" in i) DEFAULT_IP="${OPTARG}" @@ -146,6 +159,9 @@ while getopts ":D:i:-: " o; do D) OSM_DEVOPS="${OPTARG}" ;; + p) + DOCKER_PROXY_URL="${OPTARG}" + ;; -) [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 @@ -168,14 +184,17 @@ done DEBUG_INSTALL=${DEBUG_INSTALL:-} DEFAULT_IP=${DEFAULT_IP:-"127.0.0.1"} OSM_DEVOPS=${OSM_DEVOPS:-"/usr/share/osm-devops"} +DOCKER_PROXY_URL=${DOCKER_PROXY_URL=-} echo "DEBUG_INSTALL=${DEBUG_INSTALL}" echo "DEFAULT_IP=${DEFAULT_IP}" echo "OSM_DEVOPS=${OSM_DEVOPS}" +echo "DOCKER_PROXY_URL=${DOCKER_PROXY_URL}" echo "HOME=$HOME" source $OSM_DEVOPS/common/logging source $OSM_DEVOPS/common/track +configure_registry install_k3s track k8scluster k3s_install_ok check_for_readiness -- 2.25.1