物联网架构成长之路(45)-容器管理平台Rancher
0.前言
按照上一篇博客,我已经把需要下载的rancher docker 依赖镜像下载上传到Harbor了。
1. 安装
执行如下,实现一键安装
1 docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher/ rancher/rancher:stable
具体看这个文档 https://rancher.com/docs/rancher/v2.x/en/
后续所有练习都是基于本地仓库执行,方便后面测试
1 docker pull 172.16.23.203:20000/rancher/rancher:v2.3.2 2 docker tag 172.16.23.203:20000/rancher/rancher:v2.3.2 rancher/rancher:v2.3.2 3 docker rmi 172.16.23.203:20000/rancher/rancher:v2.3.2 4 docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher/ rancher/rancher:v2.3.2
执行以下命令,然后等一段时间,运行rancher还需要初始化1-2分钟。然后就可以访问了
1 apt-get install -y docker.io 2 wget http://172.16.23.203/res/docker-compose 3 chmod +x docker-compose 4 cp docker-compose /usr/local/bin 5 6 cat >/etc/docker/daemon.json <<-EOF 7 { 8 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"], 9 "insecure-registries": ["http://172.16.23.203:20000"] 10 } 11 EOF 12 systemctl daemon-reload 13 systemctl restart docker 14 15 docker login 172.16.23.203:20000 -u admin -p 123456 16 17 #install rancher 18 docker pull 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 19 docker tag 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 rancher/rancher-agent:v2.3.2 20 docker rmi 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 21 22 docker pull 172.16.23.203:20000/rancher/rancher:v2.3.2 23 docker tag 172.16.23.203:20000/rancher/rancher:v2.3.2 rancher/rancher:v2.3.2 24 docker rmi 172.16.23.203:20000/rancher/rancher:v2.3.2 25 docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher/ rancher/rancher:v2.3.2
创建一个集群 Add Cluster , 选择Custom 本地节点方式
填写Cluster Name后,就下一步。在 Node Options 角色部分,就全选。其中Worker角色,表示可以在该节点安装Pod。其他两个就是一些集群的配置信息。
用VMs创建一台新的虚拟机,执行以下脚本(注,每个人的脚本都有所不一样)
1 apt-get install -y docker.io 2 wget http://172.16.23.203/res/docker-compose 3 chmod +x docker-compose 4 cp docker-compose /usr/local/bin 5 6 cat >/etc/docker/daemon.json <<-EOF 7 { 8 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"], 9 "insecure-registries": ["http://172.16.23.203:20000"] 10 } 11 EOF 12 systemctl daemon-reload 13 systemctl restart docker 14 15 docker login 172.16.23.203:20000 -u admin -p 123456 16 17 #install rancher 18 #docker pull 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 19 #docker tag 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 rancher/rancher-agent:v2.3.2 20 #docker rmi 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 21 #docker pull 172.16.23.203:20000/rancher/rancher:v2.3.2 22 #docker tag 172.16.23.203:20000/rancher/rancher:v2.3.2 rancher/rancher:v2.3.2 23 #docker rmi 172.16.23.203:20000/rancher/rancher:v2.3.2 24 #docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher/ rancher/rancher:v2.3.2 25 26 #install worker node 27 docker pull 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 28 docker pull 172.16.23.203:20000/rancher/hyperkube:v1.15.5-rancher1 29 docker pull 172.16.23.203:20000/rancher/rke-tools:v0.1.50 30 docker pull 172.16.23.203:20000/rancher/calico-node:v3.7.4 31 docker pull 172.16.23.203:20000/rancher/calico-cni:v3.7.4 32 docker pull 172.16.23.203:20000/rancher/coreos-flannel:v0.11.0 33 docker pull 172.16.23.203:20000/rancher/coreos-etcd:v3.3.10-rancher1 34 docker pull 172.16.23.203:20000/rancher/pause:3.1 35 docker pull 172.16.23.203:20000/rancher/metrics-server:v0.3.3 36 docker pull 172.16.23.203:20000/rancher/coredns-coredns:1.3.1 37 docker pull 172.16.23.203:20000/rancher/cluster-proportional-autoscaler:1.3.0 38 docker pull 172.16.23.203:20000/rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1 39 docker tag 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 rancher/rancher-agent:v2.3.2 40 docker tag 172.16.23.203:20000/rancher/hyperkube:v1.15.5-rancher1 rancher/hyperkube:v1.15.5-rancher1 41 docker tag 172.16.23.203:20000/rancher/rke-tools:v0.1.50 rancher/rke-tools:v0.1.50 42 docker tag 172.16.23.203:20000/rancher/calico-node:v3.7.4 rancher/calico-node:v3.7.4 43 docker tag 172.16.23.203:20000/rancher/calico-cni:v3.7.4 rancher/calico-cni:v3.7.4 44 docker tag 172.16.23.203:20000/rancher/coreos-flannel:v0.11.0 rancher/coreos-flannel:v0.11.0 45 docker tag 172.16.23.203:20000/rancher/coreos-etcd:v3.3.10-rancher1 rancher/coreos-etcd:v3.3.10-rancher1 46 docker tag 172.16.23.203:20000/rancher/pause:3.1 rancher/pause:3.1 47 docker tag 172.16.23.203:20000/rancher/metrics-server:v0.3.3 rancher/metrics-server:v0.3.3 48 docker tag 172.16.23.203:20000/rancher/coredns-coredns:1.3.1 rancher/coredns-coredns:1.3.1 49 docker tag 172.16.23.203:20000/rancher/cluster-proportional-autoscaler:1.3.0 rancher/cluster-proportional-autoscaler:1.3.0 50 docker tag 172.16.23.203:20000/rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1 rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1 51 docker rmi 172.16.23.203:20000/rancher/rancher-agent:v2.3.2 52 docker rmi 172.16.23.203:20000/rancher/hyperkube:v1.15.5-rancher1 53 docker rmi 172.16.23.203:20000/rancher/rke-tools:v0.1.50 54 docker rmi 172.16.23.203:20000/rancher/calico-node:v3.7.4 55 docker rmi 172.16.23.203:20000/rancher/calico-cni:v3.7.4 56 docker rmi 172.16.23.203:20000/rancher/coreos-flannel:v0.11.0 57 docker rmi 172.16.23.203:20000/rancher/coreos-etcd:v3.3.10-rancher1 58 docker rmi 172.16.23.203:20000/rancher/pause:3.1 59 docker rmi 172.16.23.203:20000/rancher/metrics-server:v0.3.3 60 docker rmi 172.16.23.203:20000/rancher/coredns-coredns:1.3.1 61 docker rmi 172.16.23.203:20000/rancher/cluster-proportional-autoscaler:1.3.0 62 docker rmi 172.16.23.203:20000/rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1 63 64 sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.3.2 --server https://172.16.23.103 --token xvrvrg8s6shxg6bq2qc6v42fdmjm9dsbdzbff7hnfpp5mwtlfblmsg --ca-checksum 2cb3135fa308dcbd6bf6a73632072a05c03a1a8b42afc53acc594d8b440a159b --etcd --controlplane --worker
在Worker节点执行以上命令,将在Node节点部署rancher-agent,这个过程需要等待一段时间,如果是从hub.docker.com上下载的,或者aliyuncs.com镜像下载的,也是需要花一段时间,因为下载的东西很大。
理论执行上面一句命令就可以完成节点Node的部署。但是实时没有那么简单,有时候会因为网络问题,卡住不动。我一直以为是自己的原因。还有,下载的依赖,可能有1-2G,下载也是慢,所以要查查资料,看怎么使用私有repo。哎,都是泪。
还有就是之前宿主主机系统安装过etcd,这个需要卸载掉。
同理这样的机器安装多几台,这个过程完全自动化,还是比较花时间安装和服务发现的。吃个饭回来,就基本好了。
2.说明
前面博客有说到安装Kubernetes 花了将近3天,真从入门安装到放弃。现在试一下用RKE(Rancher Kubernetes Engine) 安装k8s
Rancher 所需的文件可以到这里下载 https://www.rancher.cn/docs/rancher/v2.x/cn/install-prepare/download/
简单入门: https://www.rancher.cn/docs/rancher/v2.x/cn/overview/quick-start-guide/
3. 附录,JS生成Bash脚本
1 var list = ["rancher/rancher-agent:v2.3.2", 2 "rancher/hyperkube:v1.15.5-rancher1", 3 "rancher/rke-tools:v0.1.50", 4 "rancher/calico-node:v3.7.4", 5 "rancher/calico-cni:v3.7.4", 6 "rancher/coreos-flannel:v0.11.0", 7 "rancher/coreos-etcd:v3.3.10-rancher1", 8 "rancher/pause:3.1", 9 "rancher/metrics-server:v0.3.3", 10 "rancher/coredns-coredns:1.3.1", 11 "rancher/cluster-proportional-autoscaler:1.3.0", 12 "rancher/nginx-ingress-controller:nginx-0.25.1-rancher1", 13 "rancher/kube-api-auth:v0.1.3", 14 "rancher/coredns-coredns:1.3.1", 15 "rancher/cluster-proportional-autoscaler:1.3.0", 16 "rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1" 17 ]; 18 19 var url = "172.16.23.203:20000/"; 20 var log = ""; 21 for(var i=0; i<list.length; i++){ 22 log += "docker tag " + list[i] + " " + url + list[i] +"\n" 23 } 24 console.log(log) 25 log = ""; 26 for(var i=0; i<list.length; i++){ 27 log += "docker push " + url + list[i] +"\n" 28 } 29 console.log(log) 30 log = ""; 31 for(var i=0; i<list.length; i++){ 32 log += "docker rmi " + url + list[i] + "\n" 33 } 34 console.log(log) 35 log = ""; 36 for(var i=0; i<list.length; i++){ 37 log += "docker pull " + url + list[i] + "\n" 38 } 39 console.log(log); 40 log = ""; 41 for(var i=0; i<list.length; i++){ 42 log += "docker tag " + url + list[i] + " " + list[i] + "\n" 43 } 44 console.log(log);
本文地址: https://www.cnblogs.com/wunaozai/p/11822386.html
作者:无脑仔的小明 出处:http://www.cnblogs.com/wunaozai/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。有需要沟通的,可以站内私信,文章留言,或者关注“无脑仔的小明”公众号私信我。一定尽力回答。 |