#目的是为了方便获取k8s镜像源
#url:获取k8s镜像的地址,可自行替换
#172.16.1.199/k8s/ 为本次测试的项目地址,请自行替换
#如果只是想单纯的拉取镜像,可将“re_tag”和“re_tag”两行注释掉!

#!/bin/bash/python
# -*- coding: UTF-8 -*-
# KKCai 20200911
import os
import subprocess

url='registry.aliyuncs.com/google_containers'
version=raw_input("please enter u want version,like '1.18.3' :")
print('\033[1;36;40mURL: %s\033[0m' % url)
print('\033[1;36;40mVersion:%s\033[0m' % version)

#执行kubeadm获取所需组件对应版本号
images = subprocess.check_output("kubeadm config images list --kubernetes-version=%s |awk -F '/' '{print $2}'" % version,shell=True)
print("images:"+str(images))

#将输出的镜像版本转成列表
a = ' '.join(images.split())
image_version = a.split(' ')
print(image_version)

#执for循环将对应版本下载并重新打上tag,上传自己的私有仓库
for imagename in image_version:
        print('\033[1;31;40mImagename: %s\033[0m' % imagename)
        print('\033[1;31;40mURL: %s\033[0m' % url)
        pull_image = os.system("docker pull %s/%s" % (url,imagename))
        re_tag = os.system("docker tag %s/%s 172.16.1.199/k8s/%s" % (url,imagename,imagename))
        push_image = os.system("docker push 172.16.1.199/k8s/%s" % imagename)
        #以下这句是删除原镜像,如需删除放开注释即可
        #rmi_image = os.system("docker rmi %s/%s"  % (url,imagename))

#脚本的执行过程

[root@ko8smaster180 sh]# python pull-test.py
please enter u want version,like '1.18.3' :1.18.6
url:registry.aliyuncs.com/google_containers
version:1.18.6
W0911 11:45:30.134847   21505 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
images:kube-apiserver:v1.18.6
kube-controller-manager:v1.18.6
kube-scheduler:v1.18.6
kube-proxy:v1.18.6
pause:3.2
etcd:3.4.3-0
coredns:1.6.7

['kube-apiserver:v1.18.6', 'kube-controller-manager:v1.18.6', 'kube-scheduler:v1.18.6', 'kube-proxy:v1.18.6', 'pause:3.2', 'etcd:3.4.3-0', 'coredns:1.6.7']
kube-apiserver:v1.18.6
url:registry.aliyuncs.com/google_containers
v1.18.6: Pulling from google_containers/kube-apiserver
Digest: sha256:0524beb2e07d6a5d21eb39cb70d82bea093e5f4c9fa5c4bdf2d44e437d425b61
Status: Image is up to date for registry.aliyuncs.com/google_containers/kube-apiserver:v1.18.6
registry.aliyuncs.com/google_containers/kube-apiserver:v1.18.6
The push refers to repository [172.16.1.199/k8s/kube-apiserver]
2d99d0f31eb7: Pushed
82a5cde9d9a9: Layer already exists
v1.18.6: digest: sha256:0524beb2e07d6a5d21eb39cb70d82bea093e5f4c9fa5c4bdf2d44e437d425b61 size: 741
kube-controller-manager:v1.18.6
url:registry.aliyuncs.com/google_containers
v1.18.6: Pulling from google_containers/kube-controller-manager
Digest: sha256:c23a1de9be5a55861f85f153656f4f5f7cf92e6e68c3860bf18276bd6c95ee12
Status: Image is up to date for registry.aliyuncs.com/google_containers/kube-controller-manager:v1.18.6
registry.aliyuncs.com/google_containers/kube-controller-manager:v1.18.6
The push refers to repository [172.16.1.199/k8s/kube-controller-manager]
82d47bbb60b8: Pushed
82a5cde9d9a9: Layer already exists
v1.18.6: digest: sha256:c23a1de9be5a55861f85f153656f4f5f7cf92e6e68c3860bf18276bd6c95ee12 size: 741
kube-scheduler:v1.18.6
url:registry.aliyuncs.com/google_containers
v1.18.6: Pulling from google_containers/kube-scheduler
Digest: sha256:c88b909d0ee057f20fa2fd2f8db34ce7da76f5aa574e67f19a96c216fa2e7791
Status: Image is up to date for registry.aliyuncs.com/google_containers/kube-scheduler:v1.18.6
registry.aliyuncs.com/google_containers/kube-scheduler:v1.18.6
The push refers to repository [172.16.1.199/k8s/kube-scheduler]
80eec301f276: Pushed
82a5cde9d9a9: Layer already exists
v1.18.6: digest: sha256:c88b909d0ee057f20fa2fd2f8db34ce7da76f5aa574e67f19a96c216fa2e7791 size: 741
kube-proxy:v1.18.6
url:registry.aliyuncs.com/google_containers
v1.18.6: Pulling from google_containers/kube-proxy
Digest: sha256:9bfc9de824684a32c1c3187e29dc632327938acdc53f098d5c45357a3a329f34
Status: Image is up to date for registry.aliyuncs.com/google_containers/kube-proxy:v1.18.6
registry.aliyuncs.com/google_containers/kube-proxy:v1.18.6
The push refers to repository [172.16.1.199/k8s/kube-proxy]
602805206b58: Pushed
d57a645c2b0c: Pushed
dea351e760ec: Pushed
a35a0b8b55f5: Pushed
f378e9487360: Pushed
a2b38eae1b39: Pushed
82a5cde9d9a9: Mounted from k8s/kube-scheduler
v1.18.6: digest: sha256:9bfc9de824684a32c1c3187e29dc632327938acdc53f098d5c45357a3a329f34 size: 1786
pause:3.2
url:registry.aliyuncs.com/google_containers
3.2: Pulling from google_containers/pause
Digest: sha256:4a1c4b21597c1b4415bdbecb28a3296c6b5e23ca4f9feeb599860a1dac6a0108
Status: Image is up to date for registry.aliyuncs.com/google_containers/pause:3.2
registry.aliyuncs.com/google_containers/pause:3.2
The push refers to repository [172.16.1.199/k8s/pause]
ba0dae6243cc: Layer already exists
3.2: digest: sha256:4a1c4b21597c1b4415bdbecb28a3296c6b5e23ca4f9feeb599860a1dac6a0108 size: 526
etcd:3.4.3-0
url:registry.aliyuncs.com/google_containers
3.4.3-0: Pulling from google_containers/etcd
Digest: sha256:4198ba6f82f642dfd18ecf840ee37afb9df4b596f06eef20e44d0aec4ea27216
Status: Image is up to date for registry.aliyuncs.com/google_containers/etcd:3.4.3-0
registry.aliyuncs.com/google_containers/etcd:3.4.3-0
The push refers to repository [172.16.1.199/k8s/etcd]
1b2bc745b46f: Layer already exists
ce04b89b7def: Layer already exists
fe9a8b4f1dcc: Layer already exists
3.4.3-0: digest: sha256:4198ba6f82f642dfd18ecf840ee37afb9df4b596f06eef20e44d0aec4ea27216 size: 952
coredns:1.6.7
url:registry.aliyuncs.com/google_containers
1.6.7: Pulling from google_containers/coredns
Digest: sha256:695a5e109604331f843d2c435f488bf3f239a88aec49112d452c1cbf87e88405
Status: Image is up to date for registry.aliyuncs.com/google_containers/coredns:1.6.7
registry.aliyuncs.com/google_containers/coredns:1.6.7
The push refers to repository [172.16.1.199/k8s/coredns]
c965b38a6629: Layer already exists
225df95e717c: Layer already exists
1.6.7: digest: sha256:695a5e109604331f843d2c435f488bf3f239a88aec49112d452c1cbf87e88405 size: 739
GitHub 加速计划 / ha / harbor
10
3
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:4 个月前 )
a548ab70 Add the field extra_attrs to the p2p preheat policy for the provider to define their specified parameters when preheating. Signed-off-by: chlins <chlins.zhang@gmail.com> 10 天前
e4178753 The export CVE permission should be included in the project scope, as the API relies on project-level judgment. Signed-off-by: wang yan <wangyan@vmware.com> 11 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐