Mar 152022
 

使用内部的镜像仓库来安装k8s或者kubesphere,速度都是非常爽了。那么如何搞一个离线镜像仓库,专门用来安装k8s和kubesphere呢?

最新的版本kubekey,提供了离线安装的功能,镜像仓库,自己签发ssl证书,这种方式,还是不太方便,使用的时候。我的设想是

  • 利用DNSPod 搞到证书,搭建一个docker 原厂的Registry的服务器
  • 使用kubesphere提供的阿里云镜像列表,通过skopeo来实现镜像的直接复制到私有的仓库

目前kubesphere的镜像仓库有两个,一个是在docker hub,一个是在阿里云 hub。在国内就使用阿里云hub。需要注意的是,如果使用国内的阿里云hub,那么namespace是:kubesphereio,那么你需要在kubekey上设置一下override才行。

主要参考的是木子的文章:https://blog.k8s.li/skopeo.html

image list,我已经整理了一份,安装k8s 1.21.5+kubesphere 3.2.1 的镜像列表,放在github上。

sync.sh 文件内容。

#!/bin/bash
GREEN_COL="\\033[32;1m"
RED_COL="\\033[1;31m"
NORMAL_COL="\\033[0;39m"
SOURCE_REGISTRY=$1
TARGET_REGISTRY=$2
: ${IMAGES_LIST_FILE:="images-list.txt"}
: ${TARGET_REGISTRY:="hub.chenshake.site"}
: ${SOURCE_REGISTRY:="registry.cn-beijing.aliyuncs.com"}

BLOBS_PATH="docker/registry/v2/blobs/sha256"
REPO_PATH="docker/registry/v2/repositories"
set -eo pipefail

CURRENT_NUM=0
ALL_IMAGES="$(sed -n '/#/d;s/:/:/p' ${IMAGES_LIST_FILE} | sort -u)"
TOTAL_NUMS=$(echo "${ALL_IMAGES}" | wc -l)

skopeo_copy() {
 if skopeo copy --insecure-policy --src-tls-verify=false --dest-tls-verify=false \
 --override-arch amd64 --override-os linux -q docker://$1 docker://$2; then
 echo -e "$GREEN_COL Progress: ${CURRENT_NUM}/${TOTAL_NUMS} sync $1 to $2 successful $NORMAL_COL"
 else
 echo -e "$RED_COL Progress: ${CURRENT_NUM}/${TOTAL_NUMS} sync $1 to $2 failed $NORMAL_COL"
 exit 2
 fi
}

for image in ${ALL_IMAGES}; do
 let CURRENT_NUM=${CURRENT_NUM}+1
 skopeo_copy ${SOURCE_REGISTRY}/${image} ${TARGET_REGISTRY}/${image}
done

镜像列表

  • https://github.com/shake/shell/blob/main/images-list.txt
  • http://www.chenshake.com/to-compile-the-skopeo/

skopeo,这个工具,其实是参考木子文章,我自己编译。

curl  https://hub.chenshake.site:443/v2/_catalog | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   365  100   365    0     0   2876      0 --:--:-- --:--:-- --:--:--  2896
{
    "repositories": [
        "busybox",
        "kubesphereio/alertmanager",
        "kubesphereio/alpine",
        "kubesphereio/builder-base",
        "kubesphereio/builder-go",
        "kubesphereio/builder-maven",
        "kubesphereio/builder-nodejs",
        "kubesphereio/examples-bookinfo-productpage-v1",
        "kubesphereio/kube-apiserver",
        "kubesphereio/kube-controller-manager",
        "kubesphereio/kube-proxy",
        "kubesphereio/kube-scheduler"
    ]
}

自己的镜像仓库的镜像列表。镜像的存储,我是放在 /mnt

cd /mnt/registry/
find docker -type d -name "current" | sed 's|docker/registry/v2/repositories/||g;s|/_manifests/tags/|:|g;s|/current||g' > images.list

#查看镜像列表
# cat images.list 
kubesphereio/thanos:v0.18.0
kubesphereio/kube-events-ruler:v0.3.0
kubesphereio/python-36-centos7:v3.2.0
kubesphereio/prometheus-config-reloader:v0.43.2

busybox:latest

 Leave a Reply

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.