码迷,mamicode.com
首页 > 其他好文 > 详细

使用kubeadm离线下载k8s安装镜像

时间:2020-04-03 00:57:39      阅读:772      评论:0      收藏:0      [点我收藏+]

标签:导入   pac   serve   离线   emctl   mirrors   hang   私有仓库   comm   

1、说明
2、系统及软件版本
3、安装kubeadm
4、离线镜像
5、打包镜像
6、导入镜像


1、说明
由于使用kubeadm安装 k8s 时需要从 k8s.gcr.io 拉取镜像,但是该网站被屏蔽了,国内没法正常访问导致无法正常进行k8s的安装。
这里介绍从阿里云镜像平台拉取镜像并重新打tag的方式来绕过对 k8s.gcr.io 的访问。

2、系统及软件版本

# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false

3、安装kubeadm
(1)配置kubeadm源

# cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

(2)安装kubeadm

# yum -y install kubeadm kubectl kubelet
# systemctl enable kubelet.service

(3)获取镜像列表

# kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.18.0
k8s.gcr.io/kube-controller-manager:v1.18.0
k8s.gcr.io/kube-scheduler:v1.18.0
k8s.gcr.io/kube-proxy:v1.18.0
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.7

4、离线镜像
(1)编写脚本,从阿里云下载镜像

# cat pull-images.sh 
#!/bin/bash
images=(
    kube-apiserver:v1.18.0
    kube-controller-manager:v1.18.0
    kube-scheduler:v1.18.0
    kube-proxy:v1.18.0
    pause:3.2
    etcd:3.4.3-0
    coredns:1.6.7
)
for imageName in ${images[@]};
do
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName} k8s.gcr.io/${imageName}
    docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
done

(2)查看下载镜像

# docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy                v1.18.0             43940c34f24f        7 days ago          117MB
k8s.gcr.io/kube-apiserver            v1.18.0             74060cea7f70        7 days ago          173MB
k8s.gcr.io/kube-controller-manager   v1.18.0             d3e55153f52f        7 days ago          162MB
k8s.gcr.io/kube-scheduler            v1.18.0             a31f78c7c8ce        7 days ago          95.3MB
k8s.gcr.io/pause                     3.2                 80d28bedfe5d        6 weeks ago         683kB
k8s.gcr.io/coredns                   1.6.7               67da37a9a360        2 months ago        43.8MB
k8s.gcr.io/etcd                      3.4.3-0             303ce5db0e90        5 months ago        288MB

5、打包镜像
(1)编写脚本打包镜像

# cat save-images.sh 
#!/bin/bash
images=(
    kube-apiserver:v1.18.0
    kube-controller-manager:v1.18.0
    kube-scheduler:v1.18.0
    kube-proxy:v1.18.0
    pause:3.2
    etcd:3.4.3-0
    coredns:1.6.7
)
for imageName in ${images[@]};
do
    docker save -o `echo ${imageName}|awk -F ‘:‘ ‘{print $1}‘`.tar k8s.gcr.io/${imageName}
done

# tar czvf kubeadm-images-1.18.0.tar.gz *.tar

6、导入镜像
(1)在安装节点分别导入离线镜像或者放入私有仓库使用

# cat load-image.sh 
#!/bin/bash
ls /root/kubeadm-images-1.18.0 > /root/images-list.txt
cd /root/kubeadm-images-1.18.0
for i in $(cat /root/images-list.txt)
do
     docker load -i $i
done

(2)导入镜像
# ./load-image.sh

使用kubeadm离线下载k8s安装镜像

标签:导入   pac   serve   离线   emctl   mirrors   hang   私有仓库   comm   

原文地址:https://blog.51cto.com/hatech/2484192

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!