What is skopeo?
Skepeo is an open source container image handling tool, which is relatively general and supported by various image warehouses.
install skopeo
Refer to the official installation guide .
Export which mirrors the current helm configuration depends on
$ helm template -n monitoring -f kube-prometheus-stack.yaml ./kube-prometheus-stack | grep "image:" | awk -F 'image:' '{print $2}' | awk '{$1=$1;print}' | sed -e 's/^"//' -e 's/"$//' > images.txt
$ cat images.txt
quay.io/prometheus/node-exporter:v1.3.1
quay.io/kiwigrid/k8s-sidecar:1.19.2
quay.io/kiwigrid/k8s-sidecar:1.19.2
grafana/grafana:9.0.2
registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.5.0
quay.io/prometheus-operator/prometheus-operator:v0.57.0
quay.io/prometheus/alertmanager:v0.24.0
quay.io/prometheus/prometheus:v2.36.1
bats/bats:v1.4.1
k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
- Use the helm template to render yaml, use the script to export all dependent container images and record them
images.txt
. - You can check
images.txt
which ones do not need to be synchronized and delete them.
Prepare sync script
Prepare sync script ( sync.sh
):
#! /bin/bash
DST_IMAGE_REPO="registry.imroc.cc/prometheus"
cat images.txt | while read line
do
while :
do
skopeo sync --src=docker --dest=docker $line $DST_IMAGE_REPO
if [ "$?" == "0" ]; then
break
fi
done
done
- Modify it
DST_IMAGE_REPO
to the address and path of the target warehouse that you want to synchronize,images.txt
and the mirror images in it will be synchronized to this warehouse path.
Give the script execution permission:
chmod +x sync.sh
Log in to the warehouse
When synchronizing mirroring, regardless of the source and destination, if it involves private mirroring, you need to log in first, otherwise the synchronization will report an error.
The login method is very simple, as in docker login
the same way, specify the address of the mirror warehouse to log in:
skopeo login registry.imroc.cc
Then enter the username and password.
perform synchronization
At the end of the execution ./sync.sh
, all images can be synchronized to the target warehouse with one click. If it fails, it will keep retrying until it succeeds.
FAQ
Why not batch sync with skopeo configuration files?
Because the configuration is relatively complicated and cumbersome, it is better to use a list text directly, each line represents a mirror, and read each line through a script to synchronize separately, which is simpler.