K8s国内镜像源

来自linux中国网wiki
Evan讨论 | 贡献2020年3月8日 (日) 13:39的版本
跳到导航 跳到搜索

搭建国内镜像源

https://www.cnblogs.com/xuxinkun/p/11025020.html

阿里云镜像仓库: https://cr.console.aliyun.com

google镜像仓库: https://console.cloud.google.com/gcr/images/google-containers/GLOBAL

今天用这个好像不成功

https://blog.csdn.net/nklinsirui/article/details/80581286

https://blog.csdn.net/weixin_39961559/article/details/80739352


my_k8s_containers
https://cr.console.aliyun.com/cn-hangzhou/instances/repositories

构建一个自己的源 

用ali 的  自己也打包一下  
root@k8s-master:~# docker images 
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
registry.aliyuncs.com/google_containers/kube-apiserver            v1.14.8             1e94481e8f30        4 months ago        209MB
registry.aliyuncs.com/google_containers/kube-proxy                v1.14.8             849af609e0c6        4 months ago        82.1MB
registry.aliyuncs.com/google_containers/kube-scheduler            v1.14.8             f1e3e5f9f93e        4 months ago        81.6MB
registry.aliyuncs.com/google_containers/kube-controller-manager   v1.14.8             36a8001a79fd        4 months ago        158MB
quay.io/coreos/flannel                                            v0.11.0-amd64       ff281650a721        13 months ago       52.6MB

registry.aliyuncs.com/google_containers/coredns                   1.3.1               eb516548c180        13 months ago       40.3MB

registry.aliyuncs.com/google_containers/etcd    #pass                  3.3.10              2c4adeb21b4f        15 months ago       258MB
registry.aliyuncs.com/google_containers/pause                     3.1                 da86e6ba6ca1        2 years ago         742kB


查看 
https://console.cloud.google.com/gcr/images/google-containers/GLOBAL?pli=1

 gcr.io/google_containers/kube-apiserver-amd64:v1.10.3
FROM gcr.io/google_containers/

FROM gcr.io/google_containers/coredns:v1.3.1

coredns 构建 要选择 1.3.1 版本 么 不然不行 

registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers


构建规则后要删除  版本号不能一样 
他们的用法
 kubeadm init --apiserver-advertise-address=192.168.88.60 --image-repository registry.aliyuncs.com/google_containers --ignore-preflight-errors=all  --kubernetes-version v1.14.8 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16

docker pull registry.cn-shenzhen.aliyuncs.com/cookcodeblog/kube-apiserver-amd64:v1.10.3

sudo docker pull registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers:latest


我随便打包了 用 lastest 构建的 居然可以么 
 kubeadm init --apiserver-advertise-address=192.168.88.67 --image-repository registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers --ignore-preflight-errors=all  --kubernetes-version v1.14.8 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16

用阿里的国内源 有个问题就是如果那天没了呢  

为什么我用 docker  tag 回来的 不行呢  
理论上是可以的  有空再试试 

利用一下aliyun 搞一下  明天  
https://blog.csdn.net/weixin_33795806/article/details/92524740


如何这样做成一个源的呢   如何利用aliyun   


my_k8s_containers
https://cr.console.aliyun.com/cn-hangzhou/instances/repositories

REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
registry.aliyuncs.com/google_containers/kube-apiserver            v1.14.8             1e94481e8f30        4 months ago        209MB
registry.aliyuncs.com/google_containers/kube-proxy                v1.14.8             849af609e0c6        4 months ago        82.1MB
registry.aliyuncs.com/google_containers/kube-controller-manager   v1.14.8             36a8001a79fd        4 months ago        158MB
registry.aliyuncs.com/google_containers/kube-scheduler            v1.14.8             f1e3e5f9f93e        4 months ago        81.6MB
registry.aliyuncs.com/google_containers/coredns                   1.3.1               eb516548c180        13 months ago       40.3MB
registry.aliyuncs.com/google_containers/etcd                      3.3.10              2c4adeb21b4f        15 months ago       258MB
registry.aliyuncs.com/google_containers/pause                     3.1                 da86e6ba6ca1        2 years ago         742kB






#pull自己的hub.docker  images 
docker pull  evan886/kube-apiserver:v1.17.3
docker pull evan886/kube-controller-manager:v1.17.3  
docker pull evan886/kube-scheduler:v1.17.3
docker pull  evan886/kube-proxy:v1.17.3
docker pull evan886/pause:3.1

docker pull evan886/etcd:3.4.3-0
docker pull  evan886/coredns:1.6.5
   
   
   #on k8s master 
 docker pull evan886/etcd:3.4.3-0
 docker pull  evan886/coredns:1.6.5
 docker pull evan886/kube-proxy:v1.17.3
cat >>/etc/hosts <<EOF
192.168.88.60  k8s-master
192.168.88.61  k8s-node1
192.168.88.62  k8s-node2
EOF




apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 

cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF 
apt-get update
apt-get install -y kubelet kubeadm kubectl


cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF  


暂时放弃   国内全部是 14 
华为这个 kubeadm version: 1.14.x


cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.huaweicloud.com/kubernetes/apt/ kubernetes-xenial main
EOF


#这个为什么不行 
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.huaweicloud.com/kubernetes/apt/ kubernetes-xenial main
EOF 

apt  install gnupg  -y  
 curl -s https://mirrors.huaweicloud.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
#4、更新索引文件并安装kubernetes
sudo apt update
sudo apt install -y kubeadm kubelet kubectl 


ens18

192.168.88.91
255.255.255.0 

192.168.88.255



route 
192.168.88.1

cat >>/etc/hosts <<EOF
192.168.11.67  k8s-master
192.168.88.68  k8s-node1
192.168.88.69  k8s-node2
EOF



#完全复制我的那个就可以  应该是格式  最后的 EOF的问题  这个要笔记一下 昨晚的也是  
cp /etc/network/interfaces  interfacesevan
cat >>/etc/network/interfaces <<EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
auto ens18
allow-hotplug ens18
iface ens18 inet static 
address 192.168.88.68
netmask 255.255.255.0 
gateway 192.168.88.1 
EOF


echo '# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
iface ens18 inet static 
address 192.168.88.69
netmask 255.255.255.0 
gateway 192.168.88.1 '  >/etc/network/interfaces


这个不行的 
cat >/etc/network/interfaces <EOF
#cat >>/etc/network/interfaces <<EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
iface ens18 inet static 
address 192.168.88.69
netmask 255.255.255.0 
gateway 192.168.88.1 
EOF





auto ens18
allow-hotplug ens18
iface ens18 inet static 
address 192.168.88.68
netmask 255.255.255.0 
gateway 192.168.88.1 

auto lo
iface lo inet loopback

sudo hostnamectl set-hostname "k8s-master"
sudo hostnamectl set-hostname k8s-node1
sudo hostnamectl set-hostname k8s-node2





kubeadm init --apiserver-advertise-address=192.168.88.60 --image-repository registry.aliyuncs.com/google_containers --ignore-preflight-errors=all  --kubernetes-version v1.14.8 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16


Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.88.60:6443 --token h4far6.i4ku7uz328vjc8nh \
    --discovery-token-ca-cert-hash sha256:c05dc83b02791ad395276ba61328df629f2383e65313d4ef8c8634a8ac0d2d14 


好像国内的都是 1.14.2 不过也够了 不要太新 


su - evan 
mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo "source <(kubectl completion bash)" >> ~/.bashrc
exit 

# 对于root用户 这省不能少 不然  #  kubectl  apply -f kube-flannel.yml  The connection to the server localhost:8080 was refused - did you specify the right host or port?

export KUBECONFIG=/etc/kubernetes/admin.conf
#也可以直接放到~/.bash_profile
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile




kubeadm init --kubernetes-version=1.14.2 \

--apiserver-advertise-address=10.10.10.10 \

--image-repository registry.aliyuncs.com/google_containers \

--service-cidr=10.1.0.0/16 \

--pod-network-cidr=10.244.0.0/16

已有的

  1. aliyun