Configuration requirements

For Kubernetes beginners, it is recommended to purchase the following configuration from aliyun :(you can also use your own virtual machine, private cloud and other Linux environments that are most easily available to you)

  • 3 2-core 4G ECS (burst performance instance T5 ECS.T5-C1m2. Large or equivalent configuration, about 0.4 yuan/hour per unit, no charge when downtime)
  • Cent OS 7.6

The software version after installation is

  • Kubernetes v1.16.0
    • The calico 3.8.2
    • Nginx – ingress 1.5.5
  • Docker 18.09.7

The topology view after installation is as follows: Download the source topology file You can open this file using Axure RP 9.0

About Binary Installation

I’ll sidestep the debate over whether a binary installation is better, since there are already convenient ways to get Kubernetes images. This article uses kubernetes. IO official recommended kubeadm tool installation Kubernetes cluster.

Check centos/hostname

# execute on both master and worker nodes
cat /etc/redhat-release 
The output of hostname will be the node name of the machine in the Kubernetes cluster
Do not use localhost as the node name
hostname 
Run the lscpu command to check the CPU information
# Architecture: x86_64 This installation document does not support the ARM Architecture
# CPU(s): 2 The number of CPU cores cannot be less than 2
lscpu
Copy the code

Operating System Compatibility

CentOS version Whether this document is compatible note
7.6 😄 The authenticated
7.5 😄 The authenticated
7.4 🤔 It has been confirmed that kubelet will not start
7.3 🤔 It has been confirmed that kubelet will not start
7.2 😞 It has been confirmed that kubelet will not start

Change the hostname

If you need to modify hostname, run the following command:

# change the hostname
hostnamectl set-hostname your-new-host-name 
# check the modification result
hostnamectl status 
# set hostname resolution
echo "127.0.0.1   $(hostname)"  >>  /etc/hosts
Copy the code

Please make sure that:

  • My arbitrary node centos version is in the compatibility list
  • My arbitrary node hostname is not localhost
  • The number of CPU cores on any of my nodes is greater than or equal to 2

Install Docker/Kubelet

Please visit the kuboard. Cn/install/ins… To get the latest version of the document

Execute the following code on all nodes as root to install the software:

  • docker
  • nfs-utils
  • kubectl / kubeadm / kubelet
# execute on both master and worker nodes
curl -sSL https://kuboard.cn/install-script/v1.16.0/install-kubelet.sh | sh
Copy the code

Initialize the master node

  • Run the command as root on the Demo-master-a-1 machine

  • When initializing the master node, if you want to re-initialize the master node because some configuration steps are incorrect, run kubeadm reset first

  • The network segment used by POD_SUBNET cannot overlap the network segment of the master /worker node. The value of this field is a CIDR value. If you are not familiar with the concept of CIDR, do not change the value of this field 10.100.0.1/20

# replace X.X.X.X with the actual IP address of the master node.
The # export command is valid only in the current shell session. If you want to continue the installation process after opening a new shell window, re-execute the export command here
export MASTER_IP=x.x.x.x 
# replace apiserver.demo with the dnsName you want (master hostname is not recommended as APISERVER_NAME)
export APISERVER_NAME=apiserver.demo 
This network segment is created by Kubernetes after installation and does not exist in your physical network beforehand
exportPOD_SUBNET = 10.100.0.1/20echo "${MASTER_IP}    ${APISERVER_NAME}"  >>  /etc/hosts
curl -sSL https://kuboard.cn/install-script/v1.16.0/init-master.sh | sh
Copy the code

Check the master initialization result

Execute only on the master node
Run the following command and wait 3 to 10 minutes until all container groups are in the Running state
watch kubectl get pod -n kube-system -o wide 
Initialize the master node
kubectl get nodes -o wide
Copy the code

Initialize the worker node

Get the join command parameters

  • Execute on the master node
Execute only on the master node
kubeadm token create --print-join-command
Copy the code

You can obtain the kubeadm join command and parameters, as shown below

The output of the kubeadm token create command
kubeadm join apiserver.demo:6443  --token mpfjma.4vjjg8flqihor4vt  --discovery-token-ca-cert-hash sha256:6f7a8e40a810323672de5eee6f4d19aa2dbdb38411845a1bf5dd63485c43d303
Copy the code
  • Initialize the worker

    Execute for all worker nodes

# execute only on worker nodes
# Replace ${MASTER_IP} with the actual IP address of the master node
# replace ${APISERVER_NAME} with the APISERVER_NAME used when initializing the master node
echo "${MASTER_IP}    ${APISERVER_NAME}"  >>  /etc/hosts 
# replace the kubeadm token create command output on the master node
kubeadm join apiserver.demo:6443  --token mpfjma.4vjjg8flqihor4vt  --discovery-token-ca-cert-hash sha256:6f7a8e40a810323672de5eee6f4d19aa2dbdb38411845a1bf5dd63485c43d303
Copy the code

Check the initialization result

Execute on the master node

Execute only on the master node
kubectl get nodes -o wide
Copy the code

The following output is displayed:

[root@demo-master-a- 1 ~]# kubectl get nodes 
NAME     STATUS   ROLES    AGE     VERSION
demo-master-a-1 Ready master 5M3s v1.16.0 Demo -worker-a-1 Ready < None > 2m26s v1.16.0 demo-worker-a-2 Ready < None > 3M56s v1.16.0Copy the code
  • Remove worker node

Normally, you do not need to remove the worker node. If adding the worker node to the cluster fails, you can remove the worker node and try adding it again

Execute on the worker node to be removed

# execute only on worker nodes
kubeadm reset
Copy the code
  • Run the command on the master node demo-master-a-1
Execute only on the master node
kubectl delete node demo-worker-x-x
Copy the code
  • Replace demo-worker-x-x with the name of the worker node to be removed
  • The worker node name can be obtained by executing kubectl get nodes on demo-master-a-1

Install the Ingress Controller

  • Execute on the master node
Execute only on the master node
kubectl apply -f https://kuboard.cn/install-script/v1.16.0/nginx-ingress.yaml
Copy the code
  • Configuring Domain Name Resolution

Resolve domain *.demo.yourdomain.com to demo-worker-a-2’s IP address Z.Z.Z (or demo-worker-a-1’s IP address Y.Y.Y)

  • Verify the configuration

Visit a.demo.yourdomain.com in your browser and you will get the 404 NotFound error page

If you plan to use Kubernetes in a production environment, refer to this document Installing Ingress Controller to complete the Ingress configuration

The next step

🎉 🎉 🎉

You Have finished installing the Kubernetes cluster, Have fun!

This article is provided by kuboard. Learn more about other installation materials: kuboard.cn/install/ins…