Prepare a few machines, preferably at least 2 machines.
Here are 3 machines, 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
yum install docker -y #或者使用yum install -y docker-ce安装docker-ce版本也可
systemctl start docker && systemctl enable docker
View docker cgroup
docker info
Both docker and K8S must be consistent, otherwise an error will be reported. This article uses cgroups uniformly.
If the cgroup viewed is not cgroupfs, it needs to be modified
vim /usr/lib/systemd/system/docker.service
After the modification is complete, reload the configuration and restart docker
systemctl daemon-reload && systemctl restart docker
3. Install kubeadm
3.1 configure yum file, use domestic source, all three are executed
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
EOF
3.2 Install kubeadm, execute all three
yum -y install kubeadm-1.15.1 kubectl-1.15.1 kubelet-1.15.1
systemctl enable kubelet
3.3 Import the local mirror to avoid the initialization stuck in the
mirror downloading step. The mirror download address:
https://pan.baidu.com/s/1bUptlh1zLVQlojySXDV3BA
Password: p33b
This article places all files in the /home/k8s directory
cd /home/k8s
tar xf kubeadm-basic.images.tar.gz
You can manually enter the decompressed folder to import the images one by one, or you can use a script
cd /home/k8s
vim loadimages.sh
#脚本内容
#!/bin/bash
ls /home/k8s/kubeadm-basic.images > /root/docker-load-list.txt
cd /home/k8s/kubeadm-basic.images
for i in $(cat /root/docker-load-list.txt)
do
docker load -i $i
done
rm -f /root/docker-load-list.txt
# 保存退出脚本
sh loadimages.sh #执行脚本
3.4 Initialize the master node, this step is only executed on the master node
Export the kubeadm-config.yaml configuration file
kubeadm config print init-defaults > /etc/kubernetes/kubeadm-config.yaml
Edit the kubeadm-config.yaml file
vim /etc/kubernetes/kubeadm-config.yaml
第12行:advertiseAddress:[master ip]
第34行:kubernetesVersion: v1.15.1
第36行下增加:podSubnet: "10.244.0.0/16" #pod网段
Perform initialization
kubeadm init --config=/etc/kubernetes/kubeadm-config.yaml --experimental-upload-certs | tee kubeadm-init.log
After the initialization is successful, execute the prompt command
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
3.5 Install flannel, this step is only executed on the master connection
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl create -f kube-flannel.yml
3.6 Use the command generated by the initialization successfully, copy it to the node machine for execution, and add the node machine to the master machine