Skip to content

Instantly share code, notes, and snippets.

@An0nymous0
Last active December 24, 2018 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save An0nymous0/8b399d436b6d1132dc0cf9bc28c24d18 to your computer and use it in GitHub Desktop.
Save An0nymous0/8b399d436b6d1132dc0cf9bc28c24d18 to your computer and use it in GitHub Desktop.
images=$(cat <<EOF
k8s.gcr.io/kube-apiserver:v1.13.0
k8s.gcr.io/kube-controller-manager:v1.13.0
k8s.gcr.io/kube-scheduler:v1.13.0
k8s.gcr.io/kube-proxy:v1.13.0
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.2.24
k8s.gcr.io/coredns:1.2.6
EOF
)
eval $(echo ${images}|
sed 's/k8s\.gcr\.io/gcr.mirrors.ustc.edu.cn\/google-containers/g;s/gcr\.io/gcr.mirrors.ustc.edu.cn/g;s/\//\//g;s/ /\n/g;s/gcr.mirrors.ustc.edu.cn\./gcr.mirrors.ustc.edu.cn\//g' |
uniq |
awk '{print "docker pull "$1";"}'
)
# this code will retag all of gcr.mirrors.ustc.edu.cn's image from local e.g. gcr.mirrors.ustc.edu.cn/google-containers.federation-controller-manager-arm64:v1.3.1-beta.1
# to gcr.io/google-containers/federation-controller-manager-arm64:v1.3.1-beta.1
# k8s.gcr.io/{image}/{tag} <==> gcr.io/google-containers/{image}/{tag} <==> gcr.mirrors.ustc.edu.cn/google-containers.{image}/{tag}
for img in $(docker images --format "{{.Repository}}:{{.Tag}}"| grep "gcr.mirrors.ustc.edu.cn"); do
n=$(echo ${img}| awk -F'[/.:]' '{printf "gcr.io/%s",$6}')
image=$(echo ${img}| awk -F'[/.:]' '{printf "/%s",$7}')
tag=$(echo ${img}| awk -F'[:]' '{printf ":%s",$2}')
docker tag $img "${n}${image}${tag}"
[[ ${n} == "gcr.io/google-containers" ]] && docker tag $img "k8s.gcr.io${image}${tag}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment