I. Environmental information

CentOS Linux Release 7.6.1810 (Core) Docker Version: 18.09.6 Kubernetes: V1.14.3 Linux k8S-master 4.4.182-1.el7.elrebo. x86_64 Master IP address: 192.168.2.240 node IP address: 192.168.2.230 node IP address: 192.168.2.232Copy the code

2. Environment preparation

2.1 close the swap

swapoff -aCopy the code

2.2 Adding host resolution records for each server

Cat >>/etc/hosts<<EOF 192.168.2.240k8s-master 192.168.2.230k8s-dev-api 192.168.2.230k8s-dev-service EOFCopy the code

2.3 Configuring Kernel Parameters

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
vm.swappiness=0
EOF

sysctl --systemCopy the code


2.4 Disabling the Firewall and Selinux

sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
setenforce 0
systemctl disable firewalld
systemctl stop firewalldCopy the code

2.5 Configuring the Yum Source

cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

wget http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo -O /etc/yum.repos.d/epel.repo 
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repoCopy the code

Install the configuration software

3.1 installation docker

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-ce.x86_64
systemctl start docker
systemctl enableDocker docker --version docker version 18.09.6, build 481bC77156Copy the code

3.2 Installing kubeadm, kubelet, and kubectl

yum install -y kubelet kubeadm kubectl
systemctl enable kubeletCopy the code

3.3 Configuring Docker Parameters

  • 3.3.1 Modifying the Iptables rules of docker

sed -i "13i ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT" 
sed -i "13i ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT" /usr/lib/systemd/system/docker.service
systemctl daemon-reload 
systemctl restart docker 
Copy the code

  • 3.3.2 Modifying Docker Startup Parameters

cat << EOF > /etc/docker/daemon.json 
{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker Copy the code

4. Deploy the master node

4.1 Initializing the Master

Kubeadm init --kubernetes-version=1.14.2 \ --apiserver-advertise-address=192.168.2.240 \ --image-repository Registry.aliyuncs.com/google_containers \ - service - cidr = along / 16 \ - pod - network - cidr = 172.17.0.0/16Copy the code

There is an incident here. The highest version I had installed was 1.14.3, but I was having trouble installing it, so I chose 1.14.2

You don’t need this parameter if you can scientifically access the Internet

Specifies the IP address segment of the pod

Specifies the IP address segment of the service

This process may take several minutes, mainly to download the image (if you do not modify the docker startup parameters, there may be a warning).

4.2 The Command for Adding node to a Cluster is displayed after the initialization succeeds

Kubeadm join 192.168.2.240:6443 --token lp079f.0ybezxzzda5lct1n --discovery-token-ca-cert-hash sha256:8c16723b1d179d9423a2ae321aa1e70410272b2a01f3a871eb71f070c19e028eCopy the code

4.3 Configuring the Kubectl Tool

mkdir -p /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get nodes
kubectl get csCopy the code

4.4 Configuring network plug-ins

wget https://docs.projectcalico.org/v3.6/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networkin G / 1.7 / calico. YamlModify the configuration file
#
# - name: CALICO_IPV4POOL_CIDR
# value: "172.17.0.0/16"
Set the IP address segment of the pod
kubectl apply -y calico.yamlCopy the code

5. Deploy the Node

5.1 Initializing a Node node

Perform step 2

5.2 Installing Software

Perform step 3

5.3 Joining a Cluster

Kubeadm join 192.168.2.240:6443 --token lp079f.0ybezxzzda5lct1n --discovery-token-ca-cert-hash sha256:8c16723b1d179d9423a2ae321aa1e70410272b2a01f3a871eb71f070c19e028eCopy the code

6. Verify the cluster

[root@k8s-master kube-system]# kubectl get nodeNAME STATUS ROLES AGE VERSION k8S-dev-api Ready <none> 4d22h v1.14.3k8s-service Ready <none> 4d v1.14.3k8S-master Ready master 4 d22h v1.14.3Copy the code