2.2 创建集群
点击上面图中的添加集群按钮,进入添加集群页面
选择添加主机自建Kubernetes集群CUSTOM,输入你的集群名称,当然如果你需要配置更多,下面的成员角色、集群选项等几个tab都可展开进行详细的配置,这里我们不进行配置,直接点击下一步,进入到下一步的页面。
这里我们勾选上所有的主机角色,然后将页面中第二步里显示的命令复制到宿主机进行执行,点击右边的
图标即可复制,下面的命令是我复制出来的命令:
$ sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.1.5 --server https://192.168.225.129 --token zj7gbhp4brncd7fzx664nm4dbh6rxqt5bz2xcdt6klmcwk9xsqtxqq --ca-checksum 34a2465107c418fb8f5e6851ed28f8b518d76abc84ab82b2554158aae978ec7c --etcd --controlplane –worker
执行成功后我们的浏览器中会提示如下图所示的信息[1台新主机注册成功],之后我们便可点击完成按钮。
完成按钮点击后,会跳转到集群首页,如下图所示:
这时候你可以稍作等待,这个时间可能有点长,因为这期间会在后台给我们pull多个镜像并会启动多个容器。直到集群处于Active状态(如下图)时,说明集群创建成功了。
我们可以通过docker image ls和docker container ls看看刚才集群创建过程中都为我们拉取了哪些镜像和启动了哪些容器:
[root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE rancher/rke-tools v0.1.72 9227cf8d7365 3 weeks ago 193MB rancher/hyperkube v1.17.17-rancher2 c93b2e878d88 7 weeks ago 1.72GB rancher/nginx-ingress-controller nginx-0.35.0-rancher2 1f0ca6d99110 5 months ago 322MB rancher/rancher-agent v2.4.4 5cd32c74250a 9 months ago 292MB rancher/rancher v2.4.4 aaa41ea9b2f1 9 months ago 851MB rancher/calico-node v3.13.4 c91d49e6f044 10 months ago 261MB rancher/calico-pod2daemon-flexvol v3.13.4 c5dca18c0346 10 months ago 112MB rancher/calico-cni v3.13.4 9e1176a74e85 10 months ago 225MB rancher/coreos-flannel v0.12.0 4e9f801d2217 12 months ago 52.8MB rancher/kube-api-auth v0.1.4 96148b821282 13 months ago 37.3MB rancher/coredns-coredns 1.6.5 70f311871ae1 16 months ago 41.6MB rancher/coreos-etcd v3.4.3-rancher1 a0b920cf970d 17 months ago 83.6MB rancher/metrics-server v0.3.6 9dd718864ce6 17 months ago 39.9MB rancher/cluster-proportional-autoscaler 1.7.1 14afc47fd5af 19 months ago 40.1MB rancher/nginx-ingress-controller-defaultbackend 1.5-rancher1 b5af743e5984 2 years ago 5.13MB rancher/pause 3.1 da86e6ba6ca1 3 years ago 742kB
[root@localhost ~]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4ada54b25606 rancher/kube-api-auth "/bin/sh -c 'kube-ap…" 54 seconds ago Up 52 seconds k8s_kube-api-auth_kube-api-auth-8jd5n_cattle-system_7df5473d-ffc0-49b5-b8bd-b7b87a8b9ebd_0 1c32111f2386 rancher/nginx-ingress-controller-defaultbackend "/server" About a minute ago Up 51 seconds k8s_default-http-backend_default-http-backend-67cf578fc4-pzvbp_ingress-nginx_df030f7b-2cbc-4bbb-ba01-b5c25969369c_0 64b3dbd65378 rancher/metrics-server "/metrics-server --k…" About a minute ago Up About a minute k8s_metrics-server_metrics-server-6b55c64f86-nps9d_kube-system_742b02cb-785f-479b-8f53-5d6d0663e317_0 49f8fa966083 rancher/cluster-proportional-autoscaler "/cluster-proportion…" About a minute ago Up About a minute k8s_autoscaler_coredns-autoscaler-65bfc8d47d-2jhfp_kube-system_9090c85b-2742-431a-895e-1293229479b5_0 755e68c9baab rancher/rancher-agent:v2.4.4 "run.sh --server htt…" 2 minutes ago Up About a minute determined_cori 6b1b3592800f rancher/coredns-coredns "/coredns -conf /etc…" 2 minutes ago Up 2 minutes k8s_coredns_coredns-7c5566588d-fplr4_kube-system_8cb22117-0e32-4099-9e4d-f6fbff2d2823_0 f738f9eecc0d 5cd32c74250a "run.sh" 2 minutes ago Up 2 minutes k8s_cluster-register_cattle-cluster-agent-5cf9fb5b9b-chgz5_cattle-system_42fb4b2c-f3d0-4bf9-a6d5-0580df378d0b_0 e6107723be01 5cd32c74250a "run.sh" 2 minutes ago Up 2 minutes k8s_agent_cattle-node-agent-6gbt6_cattle-system_6b6ca509-c5f7-40bb-910c-7df85e49ad12_0 eaa1eb1795ef rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_kube-api-auth-8jd5n_cattle-system_7df5473d-ffc0-49b5-b8bd-b7b87a8b9ebd_0 7d49039a29d1 rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_cattle-node-agent-6gbt6_cattle-system_6b6ca509-c5f7-40bb-910c-7df85e49ad12_0 a4a618c793a8 rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_cattle-cluster-agent-5cf9fb5b9b-chgz5_cattle-system_42fb4b2c-f3d0-4bf9-a6d5-0580df378d0b_0 c84d393206b2 rancher/coreos-flannel "/opt/bin/flanneld -…" 2 minutes ago Up 2 minutes k8s_kube-flannel_canal-5mlt2_kube-system_0a4b39fb-0672-4d20-b5fb-ad9c44abc4c7_0 469c91631f2e rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_default-http-backend-67cf578fc4-pzvbp_ingress-nginx_df030f7b-2cbc-4bbb-ba01-b5c25969369c_0 7fba41c950bf rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_nginx-ingress-controller-l6qqp_ingress-nginx_be17807c-8d2d-49ca-a893-b6863649af63_0 5175074e2865 rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_metrics-server-6b55c64f86-nps9d_kube-system_742b02cb-785f-479b-8f53-5d6d0663e317_1 46ff3c5ee169 rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_coredns-autoscaler-65bfc8d47d-2jhfp_kube-system_9090c85b-2742-431a-895e-1293229479b5_2 2d220157f0a2 rancher/calico-node "start_runit" 2 minutes ago Up 2 minutes k8s_calico-node_canal-5mlt2_kube-system_0a4b39fb-0672-4d20-b5fb-ad9c44abc4c7_0 f0bc12480f9d rancher/pause:3.1 "/pause" 2 minutes ago Up 2 minutes k8s_POD_coredns-7c5566588d-fplr4_kube-system_8cb22117-0e32-4099-9e4d-f6fbff2d2823_2 6875061280c4 rancher/pause:3.1 "/pause" 3 minutes ago Up 3 minutes k8s_POD_canal-5mlt2_kube-system_0a4b39fb-0672-4d20-b5fb-ad9c44abc4c7_0 d9819b46e83e rancher/hyperkube:v1.17.17-rancher2 "/opt/rke-tools/entr…" 4 minutes ago Up 4 minutes kube-proxy 35e4d246c81f rancher/hyperkube:v1.17.17-rancher2 "/opt/rke-tools/entr…" 4 minutes ago Up 4 minutes kubelet c36ecc7ba765 rancher/hyperkube:v1.17.17-rancher2 "/opt/rke-tools/entr…" 4 minutes ago Up 4 minutes kube-scheduler c118bf967a5b rancher/hyperkube:v1.17.17-rancher2 "/opt/rke-tools/entr…" 4 minutes ago Up 4 minutes kube-controller-manager 9513752e64f2 rancher/hyperkube:v1.17.17-rancher2 "/opt/rke-tools/entr…" 5 minutes ago Up 5 minutes kube-apiserver 860efa29bb40 rancher/coreos-etcd:v3.4.3-rancher1 "/usr/local/bin/etcd…" 5 minutes ago Up 5 minutes etcd 7392561f54fc rancher/rancher:v2.4.4 "entrypoint.sh" 8 hours ago Up 8 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp rancher
2.3 部署服务
在上一步创建的集群中给我们分配了两个项目Default和System,接下来我们在Default项目中部署我们的服务,进入如下页面:
点击部署服务按钮,进入到部署页:
你可以在部署页中输入你的应用名称,可以指定部署多少个Pod(k8s中的概念),选择对应的镜像,然后配置各种参数策略,如果你想进行数据持久化可以到数据卷的tab中进行配置,如果你有参数的定义可以到环境变量的tab中进行指定,最后再启动它。这看起来似乎是更方便的让我们执行了docker run命令,前提是你得熟悉docker中各种命令的使用及含义。本篇实践记录中我们并没有实际的部署一个服务,更多的是演示了需要部署服务的时候它的入口在哪里,部署服务的页面中都有哪些参数可供我们配置。