Make writing a habit together! This is the second day of my participation in the “Gold Digging Day New Plan · April More text challenge”. Click here for more details.

Kubernetes can build clusters in many ways: binary, Kubeadm, Ansible automation, minikube. Minikube mode is relatively simple, but only a single node, suitable for learning the basics of Kubernetes use. Any other way to install will cause all kinds of problems. I spent a week trying all of them, and none of them worked except minikube. From centos to Ubuntu, exhausted.

The other day when I was chatting with my colleague, I told him that the study of Kubernetes ended in environment building. Colleagues mysterious smile, said to me, I have a secret, five minutes to build, 100 percent success, see your bones surprise, a pack of hot strip to sell you.

I say with disbelieving tone, hold back ™ boast force, you pour say ah. The colleague held up two fingers

  • Pull the Rancher container
  • Install Kubernetes in the Rancher interface

More than five minutes means you have a bad Internet connection. I heard it was a way I didn’t know, and immediately went home after work to try it, so I have the following record.

The host to prepare

We must ensure that the initial information of the above environment is normal, mainly including IP and host name. IP must be set to static IP, and host name must be changed to different. For details, refer to the previous article about VMware Fusion installing CentOS7 and configuring the network

Initialization is performed on k8S-master

  • Install the rancher
# 拉取rancher/rancher:v2.0.0镜像,这个是在docker hub上,不推荐使用最新的rancher镜像
docker run -d --restart=always -p 80:80 -p 443:443 rancher/rancher:v2.0.0
Copy the code
  • Configuring Time Synchronization
# yum install -y NTP ntpdate # ************ *********** # yum install -y ntp.conf Add server ntp3.aliyun.com iBurst # 192.168.143.2 to Restrict 192.168.143.2 mask 255.255.255.0 nomodify notrap # Comment out this line # RESTRICT 127.0.0.1Copy the code
  • Enabling host ports facilitates communication between hosts. These commands must be executed on all hosts
  firewall-cmd --zone=public --add-port=2379/tcp --permanent   
  firewall-cmd --zone=public --add-port=2380/tcp --permanent   
  firewall-cmd --zone=public --add-port=6443/tcp --permanent   
  firewall-cmd --zone=public --add-port=10250/tcp --permanent   
  firewall-cmd --reload
Copy the code

Other hosts are initialized

# yum install -y NTP ntpdate # yum install -y NTP ntpdate # yum install -y NTP ntpdate Add server 192.168.143.130 prefer # Comment out the line # RESTRICT 127.0.0.1 # After saving the above file, run the following command on the console to synchronize NTPQ -p onceCopy the code

Perform initialization on the Rancher

We have installed Rancher on the host, opened the browser to https://192.168.143.130, first set the admin password, and then the next step is done

Change the language to Simplified Chinese, then click the cluster in the upper left corner, and click add Cluster on the right

Select Custom to create a kubernetes cluster. If you already have a cluster, click Import to import the existing cluster

Fill in the name, leave the rest alone and click Next

Kubernetes (k8S-master) kubernetes (k8S-master) kubernetes (k8S-master) kubernetes (k8S-master) After the command is executed successfully, a host is registered in the lower left corner of the screen. Click Done

Return to the cluster interface, click the three small dots on the right of the cluster, select Edit, some versions of the upgrade shown here, click the upgrade button

Select the control and work node in this interface, and then copy the command, execute the command on other hosts, each host after execution, will show the host has been registered in the lower left corner, click save after execution. Each host is initialized after being added to a cluster. The initialization time depends on the availability of the host.

After the host is registered, we will see the cluster we have registered here above, click it and it will show as follows

Click the node to see our host machine, our three-node Kubernetes cluster is built. Is it very simple, and is the interface of the operation, very convenient, almost no mistakes.

Rancher can install Kubernetes and provides many operations, but I recommend using the kubectl command. If you’re already familiar with kubernetes, the visual interface is more efficient, and if you’re new to Kubernetes, the command line is easier to learn.

Abnormal problem

The problems that can occur during setup are machine initialization problems, such as multiple machines with the same hostname or IP address, and as long as you pay attention to these two things, there will be almost no problems.