Commit 117fd4ab authored by garciadeblas's avatar garciadeblas
Browse files

Configure docker proxy URL for K3s-based installation to overcome docker pull rate limit



Change-Id: I94dde54e4f124369daaf40ff6863b77e2fd25d23
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent 10944e87
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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,
+20 −1
Original line number Diff line number Diff line
@@ -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