K8S 1.10.1 version deployment

Prepare a few machines, preferably at least 2 machines.
I have prepared 3 machines here, one for master and two for node
1. Basic machine settings
1.1 Set host name

hostnamectl set-hostname master  #在master机器上执行
hostnamectl set-hostname node1   #在node1机器上执行
hostnamectl set-hostname node2   #在node2机器上执行

1.2 Set the time zone of three machines to ensure the accuracy of follow-up events. If the time of each machine is different, there will be many inexplicable problems in the follow-up

timedatectl set-timezone Asia/Shanghai   #在三台上都执行

1.3 Add a host to the hosts file

vim /etc/hosts  #三台机器都执行
#在打开的文件添加三行内容,内容为机器ip+名称,本文直接以master+node命名,实际可按照需求更改
#192.168.1.181 matser
#192.168.1.182 node1
#192.168.1.183 node2

1.4 It is very important to close the swap partition. If the swap partition is not closed, it will directly cause deployment failure. All three units need to be executed.

swapoff -a  
vim /etc/fstab  #将swap所在行注释掉

1.5 Modify iptables information

 echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
 echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables

1.6 Close seliux and firewalld on all nodes

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0 
systemctl disable firewalld
systemctl stop firewalld

2. Install docker.
Because the K8S version to be deployed this time is 1.10.1 version, the version is lower, so do not install the docker version too high version (pro-test 19.03 version is not compatible)

yum install docker -y
systemctl start docker && systemctl enable docker

The default installation is version 1.13 (currently the latest version is version 1.13), do not install docker-ce, docker-ce will install version 19.03 (the latest version so far)
Check docker cgroup

docker info

K8S version 1.10.1 uses cgroup driver, and systemd is recommended for versions after 1.14. Both docker and K8S must be consistent, otherwise an error will be reported.
Insert picture description here
If the viewed cgroup is not cgroupfs, it needs to be modified

vim /usr/lib/systemd/system/docker.service

Insert picture description here
After the modification is complete, reload the configuration and restart docker

systemctl daemon-reload && systemctl restart docker

3. Install kubeadm, kubectl, kubelet
3.1 Download the necessary offline packages, because if you don’t download them, the necessary mirrors will be automatically pulled when kubeadm is initialized later, and some mirrors need to be overturned to download.

Link: https://pan.baidu.com/s/15l5I1kdcr5BeSRqPPw00Bw Password: xssb
3.2 installation, all the machines need to execute this step for three days.
Note: This article puts all K8S files in the /home/k8s directory, the following code is in Remember to modify to the actual path when using

cd /home/k8s/kubernetes-1.10
tar -xvf kube-packages-1.10.1.tar
cd kube-packages-1.10.1
rpm -Uvh * --force --nodeps

Set kubelet to use cgroupfs on all kubernetes nodes, which is consistent with dockerd, otherwise kubelet will start and report an error. The
default kubelet uses cgroup-driver=systemd

sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

systemctl daemon-reload && systemctl restart kubelet

3.3 Import the image, only the necessary images are imported. If there are many subsequent images, you can consider building a harbor to store the images. This step needs to be performed on all machines for three days

docker load -i k8s-images-1.10.tar.gz

3.4 Initialize the master node, this step only needs to be executed on the master machine

kubeadm init --kubernetes-version=v1.10.1 --pod-network-cidr=10.244.0.0/16
#初始化需要执行部署的版本,和ip段

After the initialization is successful, remember to record the join command of join, and execute the command on the node node to add the node machine to the master node.
Insert picture description here
3.5 The prompt command after the initial success is executed

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

3.6 View the current deployment

kubectl get node

It can be seen that there is only one master node at this time, and the status is notready.
Insert picture description here
This is because the network plug-in has not been deployed yet. K8S can use multiple network methods, such as flannel, calico, openvswitch.
This article uses flannel network
3.7 to deploy flannel

cd /home/k8s/kubernetes-1.10
kubectl apply -f kube-flannel.yml  #配置文件可修改,本文直接使用默认配置

Wait a while after the configuration is complete, and check the node status again

kubectl get node

You can see that the status becomes normal. Insert picture description here
3.8 Add the node node to the master machine
Directly copy the command after the master node is initialized (without any modification, copy and execute directly), you can add the node node to the master machine
after a while, you can see 2 node machines
Insert picture description here
4. At this step, the cluster deployment is complete

5.dashboard deployment
directly use the three .yaml files in the offline package to complete the deployment

cd /home/k8s/kubernetes-1.10
kubectl apply -f kubernetes-dashboard-http.yaml -f admin-role.yaml -f kubernetes-dashboard-admin.rbac.yaml

After completion, check whether the host has started port 31000, if it has been started, open the K8S visualization page through ip:31000

6. The master node failed to initialize and needs to be cleaned up and redeployed

#重置kubernetes服务,重置网络,删除网络配置
kubeadm reset
systemctl stop kubelet 
systemctl stop docker 
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker

Guess you like

Origin blog.csdn.net/u010264186/article/details/107785125