1. 安装阿里云k8s yum源（全部机器）
```
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
```
```
# Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
```
```
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
```
```
systemctl enable --now kubelet
```
2. 调整kernel参数（二层的网桥在转发包时也会被iptables的FORWARD规则所过滤）（全部机器）
```
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-iptables=1
EOF
sysctl --system
```
3. 启动kubelet（全部机器）
```
systemctl daemon-reload
systemctl restart kubelet
```
4. 在选定的主节点上运行
```
kubeadm init
```
5. 在选定的主节点上运行，保存kubectl配置
```
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```
6. 之后会在命令行里返回如下命令。复制，粘贴到跑agent的服务器运行，即可完成
```
kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
```
7. 运行网络组件（全部机器）
```
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
```