Kubernetetes鏡像在國內沒法直接訪問,致使安裝費時、容易出錯、難以排查。能夠將其抓取到阿里雲上面,提早拉取(docker pull)到本地,而後再運行kubeadm安裝程序,就要快不少了。git
echo "" echo "==========================================================" echo "Pull Kubernetes 1.11.0 Images from aliyuncs.com ......" echo "==========================================================" echo "" MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings ## 拉取鏡像 docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver-amd64:v1.11.0 docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager-amd64:v1.11.0 docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler-amd64:v1.11.0 docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-proxy-amd64:v1.11.0 docker pull ${MY_REGISTRY}/k8s-gcr-io-etcd-amd64:3.2.18 docker pull ${MY_REGISTRY}/k8s-gcr-io-pause-amd64:3.1 docker pull ${MY_REGISTRY}/k8s-gcr-io-coredns:1.1.3 ## 添加Tag docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver-amd64:v1.11.0 k8s.gcr.io/kube-apiserver-amd64:v1.11.0 docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler-amd64:v1.11.0 k8s.gcr.io/kube-scheduler-amd64:v1.11.0 docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager-amd64:v1.11.0 k8s.gcr.io/kube-controller-manager-amd64:v1.11.0 docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-proxy-amd64:v1.11.0 k8s.gcr.io/kube-proxy-amd64:v1.11.0 docker tag ${MY_REGISTRY}/k8s-gcr-io-etcd-amd64:3.2.18 k8s.gcr.io/etcd-amd64:3.2.18 docker tag ${MY_REGISTRY}/k8s-gcr-io-pause-amd64:3.1 k8s.gcr.io/pause-amd64:3.1 docker tag ${MY_REGISTRY}/k8s-gcr-io-coredns:1.1.3 k8s.gcr.io/coredns:1.1.3 echo "" echo "==========================================================" echo "Pull Kubernetes 1.11.0 Images FINISHED." echo "into registry.cn-hangzhou.aliyuncs.com/openthings, " echo " by openthings@https://my.oschina.net/u/2306127." echo "==========================================================" echo ""
保存爲aliyun-get-kubeimages-1.11.0.sh,複製上面內容進去,而後運行便可。github
安裝Kubernetes1.11.0(下面以Ubuntu16.04.03LTS爲準),以下:docker
第一步,安裝Kubeadm:api
echo "添加Kubernetes安裝源認證key:" sudo curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add echo "添加Kubernetes安裝源:" sudo echo deb http://apt.kubernetes.io/ kubernetes-xenial main > /etc/apt/sources.list.d/kubernetes.list echo "更新系統軟件包列表:" sudo apt update echo "查看Kubernetes的可用版本:" apt-cache madison kubeadm echo "安裝kubeadm 1.11.0: " apt-get install -y kubeadm=1.11.0-00 kubectl=1.11.0-00 kubelet=1.11.0-00
第二步,經過kubeadm安裝Kubernetes1.11.0:bash
echo "" echo "==========================================================" echo "Setup Kubernetes Cluster 1.11.0 using kubeadm......" echo "" echo "Please visit https://my.oschina.net/u/2306127/blog/1628082" echo "==========================================================" echo "" echo "Close Swap, K8S required." sudo swapoff -a echo "請sudo nano /etc/fstab中永久刪除或關閉swap分區,使用 # 註釋掉便可。" echo "" echo "Close IPTable,K8S required." sudo iptables -F echo "" echo "" echo "Setup Kubernetes Cluster using kubeadm..." sudo kubeadm init --kubernetes-version=v1.11.0 –pod-network-cidr 10.244.0.0/16 --feature-gates CoreDNS=true echo "" echo "Install flannel CNI network driver..." sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml echo "" echo "Kubernetes status..." kubectl get pod --all-namespaces echo "" echo "==========================================================" echo "Please visit https://my.oschina.net/u/2306127/blog/1628082" echo "==========================================================" echo ""
echo "" echo "==========================================================" echo "Push Kubernetes 1.11.0 Images into aliyuncs.com ......" echo "==========================================================" echo "" echo "docker tag to openthings ..." ## 添加Tag for registry.cn-hangzhou.aliyuncs.com/openthings MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings docker tag k8s.gcr.io/kube-apiserver-amd64:v1.11.0 ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver-amd64:v1.11.0 docker tag k8s.gcr.io/kube-scheduler-amd64:v1.11.0 ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler-amd64:v1.11.0 docker tag k8s.gcr.io/kube-controller-manager-amd64:v1.11.0 ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager-amd64:v1.11.0 docker tag k8s.gcr.io/kube-proxy-amd64:v1.11.0 ${MY_REGISTRY}/k8s-gcr-io-kube-proxy-amd64:v1.11.0 docker tag k8s.gcr.io/etcd-amd64:3.2.18 ${MY_REGISTRY}/k8s-gcr-io-etcd-amd64:3.2.18 docker tag k8s.gcr.io/pause-amd64:3.1 ${MY_REGISTRY}/k8s-gcr-io-pause-amd64:3.1 docker tag k8s.gcr.io/coredns:1.1.3 ${MY_REGISTRY}/k8s-gcr-io-coredns:1.1.3 echo "" echo "==========================================================" echo "" ## Push鏡像 echo "" echo "1.k8s-kube-apiserver-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver-amd64:v1.11.0 echo "" echo "2.k8s-kube-controller-manager-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager-amd64:v1.11.0 echo "" echo "3.k8s-kube-scheduler-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler-amd64:v1.11.0 echo "" echo "4.k8s-kube-proxy-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-kube-proxy-amd64:v1.11.0 echo "" echo "5.k8s-etcd-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-etcd-amd64:3.2.18 echo "" echo "6.k8s-pause-amd64" docker push ${MY_REGISTRY}/k8s-gcr-io-pause-amd64:3.1 echo "" echo "7.k8s-coredns" docker push ${MY_REGISTRY}/k8s-gcr-io-coredns:1.1.3 echo "" echo "==========================================================" echo "Push Kubernetes 1.11.0 Images FINISHED." echo "into registry.cn-hangzhou.aliyuncs.com/openthings, " echo " by openthings@https://my.oschina.net/u/2306127." echo "==========================================================" echo ""
上面的腳本須要在可以同時訪問gcr.io和阿里雲的registry服務的機器上運行。鏡像倉庫服務我在這裏用的阿里雲的{華東1}的容器倉庫服務(registry.cn-hangzhou.aliyuncs.com,須要注意:阿里雲的每一個區都有registry服務區,是相互獨立的),你能夠改爲本身的地址。app