From 2efb98b6dc5a9f71900a4cdd105cd18b4b9fd7e2 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Wed, 21 Aug 2024 21:19:36 +0200 Subject: [PATCH] Configure docker private registry for K3s-based installation Change-Id: Iaf3a678f337b0241160b57c4876ffc671a4a3cbf Signed-off-by: garciadeblas --- installers/full_install_osm.sh | 4 ++++ installers/install_k3s_cluster.sh | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 6cde383f..ee51e2f6 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -430,6 +430,9 @@ function install_k8s_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}" + [ -n "${DOCKER_REGISTRY_URL}" ] && K3S_INSTALL_OPTS="${K3S_INSTALL_OPTS} -d ${DOCKER_REGISTRY_URL}" + [ -n "${DOCKER_REGISTRY_USER}" ] && K3S_INSTALL_OPTS="${K3S_INSTALL_OPTS} -u ${DOCKER_REGISTRY_USER}" + [ -n "${DOCKER_REGISTRY_PASSWORD}" ] && K3S_INSTALL_OPTS="${K3S_INSTALL_OPTS} -P ${DOCKER_REGISTRY_PASSWORD}" # 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, @@ -500,6 +503,7 @@ function install_osm() { echo "Kubeadm requires docker, so docker will be installed." fi install_docker_ce + [ -n "${DOCKER_REGISTRY_URL}" ] && docker_login fi track docker_ce docker_ce_ok diff --git a/installers/install_k3s_cluster.sh b/installers/install_k3s_cluster.sh index fea91f41..86bc1353 100755 --- a/installers/install_k3s_cluster.sh +++ b/installers/install_k3s_cluster.sh @@ -27,6 +27,16 @@ mirrors: docker.io: endpoint: - "${DOCKER_PROXY_URL}" +EOF + fi + if [ -n "${DOCKER_REGISTRY_URL}" ]; then + echo "Configuring docker private registry in /etc/rancher/k3s/registries.yaml" + cat << EOF | sudo tee -a /etc/rancher/k3s/registries.yaml > /dev/null +configs: + ${DOCKER_REGISTRY_URL}: + auth: + username: ${DOCKER_REGISTRY_USER} + password: ${DOCKER_REGISTRY_PASSWORD} EOF fi } @@ -151,7 +161,7 @@ function save_kubeconfig() { } # main -while getopts ":D:i:p:-: " o; do +while getopts ":D:i:p:d:u:P:-: " o; do case "${o}" in i) DEFAULT_IP="${OPTARG}" @@ -162,6 +172,15 @@ while getopts ":D:i:p:-: " o; do p) DOCKER_PROXY_URL="${OPTARG}" ;; + d) + DOCKER_REGISTRY_URL="${OPTARG}" + ;; + u) + DOCKER_REGISTRY_USER="${OPTARG}" + ;; + P) + DOCKER_REGISTRY_PASSWORD="${OPTARG}" + ;; -) [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 @@ -185,10 +204,15 @@ 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=-} +DOCKER_REGISTRY_URL=${DOCKER_REGISTRY_URL=-} +DOCKER_REGISTRY_USER=${DOCKER_REGISTRY_USER=-} +DOCKER_REGISTRY_PASSWORD=${DOCKER_REGISTRY_PASSWORD=-} echo "DEBUG_INSTALL=${DEBUG_INSTALL}" echo "DEFAULT_IP=${DEFAULT_IP}" echo "OSM_DEVOPS=${OSM_DEVOPS}" echo "DOCKER_PROXY_URL=${DOCKER_PROXY_URL}" +echo "DOCKER_REGISTRY_URL=${DOCKER_REGISTRY_URL}" +echo "DOCKER_REGISTRY_USER=${DOCKER_REGISTRY_USER}" echo "HOME=$HOME" source $OSM_DEVOPS/common/logging -- 2.25.1