1、安装Docker
[root@localhost ~]# docker -v Docker version 18.09.3, build 774a1f4
2、使用Docker运行Rancher : stable
[root@localhost ~]# docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:stable Unable to find image 'rancher/rancher:stable' locally stable: Pulling from rancher/rancher 6abc03819f3e: Pull complete 05731e63f211: Pull complete 0bd67c50d6be: Pull complete 67f26e57c9aa: Pull complete 0ae4a6d5c8c7: Pull complete bb5f8b86a713: Pull complete d67152696db5: Pull complete aa348b037a41: Pull complete 474a642b0dfb: Pull complete 0ee278656a03: Pull complete e71dded0779c: Pull complete bdd3e3cfbd43: Pull complete Digest: sha256:97a6bac34ed21b676486cbf7f848fc4483082734a91447cc01b939aab2d69235 Status: Downloaded newer image for rancher/rancher:stable 5851fb343033652352f1ac31e9302a12e17aa98cc1bac8e972fb61387e41551b [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5851fb343033 rancher/rancher:stable "entrypoint.sh" 9 seconds ago Up 8 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp pedantic_jones [root@localhost ~]#
3、查看ip
[root@localhost ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:eb:e3:df brd ff:ff:ff:ff:ff:ff inet 192.168.238.128/24 brd 192.168.238.255 scope global noprefixroute dynamic ens33 valid_lft 955sec preferred_lft 955sec inet6 fe80::382:b55c:dfbd:188c/64 scope link noprefixroute valid_lft forever preferred_lft forever inet6 fe80::3f0:5508:6df7:8f0/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:0d:cd:da:e3 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:dff:fecd:dae3/64 scope link valid_lft forever preferred_lft forever 95: veth26bc295@if94: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default link/ether b6:20:48:1e:c0:51 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 fe80::b420:48ff:fe1e:c051/64 scope link valid_lft forever preferred_lft forever [root@localhost ~]#
4、访问Rancher UI
设置admin密码,这里设置为123456
设置Rancher Server URL,Rancher Server URL是agent节点注册到rancher serverd的地址,需要保证这个地址能够被agent主机访问,不要设置为127.0.0.1
或者localhost
。
这里设置为192.168.238.128
跳转到主页 https://192.168.64.136/g/clusters
创建K8s集群:
点击custom,添加集群名称k8sdemo,k8s版本默认v1.13.5-rancher1-3,网络组件默认canal,点击下一步
保存成功后,勾选Etcd和Control
保存命令:sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.4 --server https://192.168.238.128 --token hrc8xsh7d7j9gtgdspnnrvqk8g79zh4dmtd5rw5r9hlncdcbdjwtxd --ca-checksum 74c3ce0f92c8f19d29ce3cb8c7c393643f35b7b21489b652278d200786954d88 --etcd --controlplane --worker
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.4 --server https://192.168.238.128 --token hrc8xsh7d7j9gtgdspnnrvqk8g79zh4dmtd5rw5r9hlncdcbdjwtxd --ca-checksum 74c3ce0f92c8f19d29ce3cb8c7c393643f35b7b21489b652278d200786954d88 --etcd --controlplane --worker
rancher_server 运行上述命令:
[root@localhost ~]# sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.4 --server https://192.168.238.128 --token nzp8h5b6m5jfvmtjfm6m6c5vsscj6hwvjlkw6rsppc6pjd8hqtvrvx --ca-checksum 1251b9cc092d779314aece7f78b6da2444df28129cc5ac812d33b9f948c9837e --etcd --controlplane --worker Unable to find image 'rancher/rancher-agent:v2.2.4' locally v2.2.4: Pulling from rancher/rancher-agent 6abc03819f3e: Already exists 05731e63f211: Already exists 0bd67c50d6be: Already exists e7e8247bd935: Pull complete 1a35389393bc: Pull complete 7891f5237e19: Pull complete 480c5d8e76a1: Pull complete a985e4338da5: Pull complete 786480892ac4: Pull complete Digest: sha256:a895cb47ae81a641db64a3f727fe371cc6f2be7e8c98ee03f6f6a911b9d572ab Status: Downloaded newer image for rancher/rancher-agent:v2.2.4 817c3d9c6de33c2236d88eb58d5b0e4d18822cd09d08563482aaf37e26264136 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 724d6ca9fc42 rancher/rancher-agent:v2.2.4 "run.sh --server htt…" 2 minutes ago Up 2 minutes adoring_cartwright ad7e8cbc0471 rancher/rancher-agent:v2.2.4 "run.sh -- share-roo…" 2 minutes ago Up 2 minutes share-mnt 817c3d9c6de3 rancher/rancher-agent:v2.2.4 "run.sh --server htt…" 2 minutes ago Up 2 minutes vigorous_newton 5851fb343033 rancher/rancher:stable "entrypoint.sh" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp pedantic_jones [root@localhost ~]#
点击完成,提示一台新主机注册成功。
等待部署完成。