如何借用阿里云构建国外镜像

如何借用阿里云构建国外镜像

前言

最近搭建Kubespray,在使用Kubernetes和docker的时候会出现一些镜像无法拉取或者速度较慢的情况,k8s.gcr.io镜像更加离谱,科学上网都无法拉取,会抛出类似以下错误信息。

fatal: [node1 -> 192.168.1.104]: FAILED! => {
    "attempts": 4,
    "changed": true,
    "cmd": [
        "/usr/bin/docker",
        "pull",
        "k8s.gcr.io/coredns:1.7.0"
    ],
    "delta": "0:00:15.116121",
    "end": "2021-01-16 11:35:22.398178",
    "invocation": {
        "module_args": {
            "_raw_params": "/usr/bin/docker pull k8s.gcr.io/coredns:1.7.0",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2021-01-16 11:35:07.282057",
    "stderr": "Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)",
    "stderr_lines": [
        "Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
    ],
    "stdout": "",
    "stdout_lines": []
}

复制代码

网上也找了不少镜像源,好多都失效了,Azure中国的镜像已失效,中科大的也不是很稳定。

于是只能采取曲中的办法,借用 阿里云构建镜像

创建阿里云镜像库

首先进入阿里云 容器镜像服务器

创建命名空间

温馨提示,命名空间最多只能3个

创建镜像库

构建成功如下图:

添加规则

点击立即构建

OK,到此,整个镜像就构建好了

镜像构建Dockerfile

这是我仓库的地址

如 k8s-dns-node-cache/Dockerfile 只有如下简单一行代码即可

FROM k8s.gcr.io/dns/k8s-dns-node-cache:1.16.0
复制代码

Docker拉取镜像

# 拉取镜像
[root@k8s-master k8s]$ docker pull registry.cn-hangzhou.aliyuncs.com/owater/k8s-dns-node-cache:1.16.0

# 镜像打tag
[root@k8s-master k8s]$ docker tag registry.cn-hangzhou.aliyuncs.com/owater/k8s-dns-node-cache:1.16.0 k8s.gcr.io/dns/k8s-dns-node-cache:1.16.0
复制代码

注意:tag得和国外镜像对应才行,如FROM k8s.gcr.io/dns/k8s-dns-node-cache:1.16.0,那tag就是k8s.gcr.io/dns/k8s-dns-node-cache:1.16.0

分类:
后端
标签: