Rancher Server deployment using local multi-node cluster K8S

When I first started my Kubernetes trip, I was looking for a way to set up local deployment environment. Many people often use minikube or microk8s, both for new users to operate in a single-node cluster environment. But when I already know the basics, both of which is clearly not enough, I need to be able to run further to find the local multi-node cluster, the production environment more similar platform. To this end, I have access to many resources, and finally I found Rancher Server. Next, I'll show you how I set up my local K8S multi-node cluster.

Prepare master node and worker nodes of a virtual machine

The figure shows the architecture of a cluster, a worker master node and three nodes. To try to use ingress controller such as load balancing, session remains, host affinity and other cross-node function, which is the minimum configuration.

Rancher Server installation is not complicated, it is packaged as a docker image, and can be run as a container. The basic configuration of a node is running docker CE daemon on Linux virtual machines. In this case, I chose to use Ubuntu 18.04 LTS (Please refer to the specific requirements of the node Rancher official document: https: //rancher.com/docs/rancher/v2.x/en/installation/requirements/). When I finished the first VM settings, I simply copy it to the other three. If you and I are the same operation, refer to below two tips:

  • Install the specified version Docker: https: //docs.docker.com/install/linux/docker-ce/ubuntu/

  • After the Clone virtual machine, change the Ubuntu hostname: https: //linuxize.com/post/how-to-change-hostname-on-ubuntu-18-04/

Eventually, the four nodes on my computer (i5,24G RAM) starts, and assign the following resources.

  • Master节点(2 core、4G RAM、Ubuntu 18.04 + Docker CE 18.09) x 1

  • Worker节点(2 core, 3G RAM, Ubuntu 18.04 + Docker CE 18.09) x 3

在master节点上启动Rancher server

sudo docker run --restart=unless-stopped \
  -p 81:80 -p 444:443 rancher/rancher

以上命令可以启动Rancher server容器,并且将其运行在master节点上。默认状态下,nginx ingress controller会嵌入到worker节点中,并且绑定端口80和443。因此我将Rancger server发布到端口81和444或其他端口,以避免端口冲突。

完成Rancher server初始设置

首先,使用master节点IP地址和端口444启动Rancher server控制台,它会要求设置管理员密码。

接着,确认worker节点到达Rancher server的URL。这里为了方便我直接使用master节点IP地址作为URL。完成了初始设置后,Rancher server就可以添加新集群了。

创建一个新的K8S集群和master节点

因为我想要在本地虚拟机上运行K8S集群而不是在云端,所以选择“自定义”的选项(即上方说明为“ From my own existing nodes”),然后新集群的云提供商选项选为“None”。

在ubuntu虚拟机上复制并运行docker命令来启动master节点。一个master节点至少要有etcd和control,如果你打算创建一个单节点集群,需要选择所有3个角色并更改命令。

运行docker命令之后,新节点将显示在Rancher Server控制台上,配置这一节点需要花费一些时间,一旦配置完成,状态将变为active。

创建worker节点

对于worker节点,我们仅需要在节点选项选择“Worker”角色,然后在3个worker节点的Ubuntu虚拟机上复制并运行docker命令。

最后,在我的电脑上多节点集群已经准备就绪。

安装kubectl工具来管理新的K8S集群

新集群的Kubernetes版本时v1.14.6,你可以在上面的截图内看到。为了更好地将kubectl工具版本与集群匹配,在master节点上运行以下命令,以安装特定版本:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.6/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Kubectl工具需要一个kubeconfig文件与集群连接,新集群地kubeconfig文件可以在Rancher Server的控制台中找到。

复制以上kubeconfig文件,并保存为~/.kube/config文件。随后kubectl就能够获取集群信息。

有关kubectl的安装和配置可以参考以下连接:

  • 安装和设置kubectl:https://kubernetes.io/docs/tasks/tools/install-kubectl/

  • 配置kubectl以访问多集群:https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

原文链接:

https://medium.com/@kwonghung.yip/setup-local-kubernetes-multi-node-cluster-with-rancher-server-fdb7a0669b5c

Guess you like

Origin www.cnblogs.com/rancherlabs/p/12165449.html