环境准备:
systemctl stop firewalld systemctl disable firewalld 关闭selinux sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0 #关闭swap swapoff -a yes | cp /etc/fstab /etc/fstab_bak cat /etc/fstab_bak | grep -v swap > /etc/fstab echo "* soft nofile 190000" >> /etc/security/limits.conf echo "* hard nofile 200000" >> /etc/security/limits.conf echo "* soft nproc 252144" >> /etc/security/limits.conf echo "* hadr nproc 262144" >> /etc/security/limits.conf 配置内核参数 cat > /etc/sysctl.d/k8s.conf <<EOF 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 --system
1、导入Kubernetes的镜像
docker load -i k8s-master.tar
2、安装kubeadm(所有节点)
tar -xf kubernetes-server-linux-amd64-1.14.tar.gz cd kubernetes/server/bin cp -ar kubelet kubeadm kubectl /usr/bin/
3、配置kubeadm启动文件
cat >/usr/lib/systemd/system/kubelet.service <<EOF [Unit] Description=kubelet: The Kubernetes Node Agent Documentation=https://kubernetes.io/docs/ [Service] ExecStart=/usr/bin/kubelet Restart=always StartLimitInterval=0 RestartSec=10 [Install] WantedBy=multi-user.target EOF #注意ExecStart内容换行 mkdir -p /usr/lib/systemd/system/kubelet.service.d/ cat >/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf <<EOF [Service] Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml" EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env EnvironmentFile=-/etc/sysconfig/kubelet ExecStart= ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS EOF #导入cni-plugins mv cni /opt/ #启动kubelet systemctl enable kubelet && systemctl restart kubelet
4、创建初始化配置文件 可以使用如下命令生成初始化配置文件(修改相应配置文件)
kubeadm config print init-defaults > kubeadm-config.yaml
5、初始化Master01节点
这里追加tee命令将初始化日志输出到kubeadm-init.log中以备用(可选)。
kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs | tee kubeadm-init.log
6、添加node
#创建目录
mkdir /etc/kubernetes/manifests docker load -i k8s-node.tar
#加入k8s cluster
kubeadm join 192.168.247.154:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:c80957ecef9382082b9b56833ad6cb464492388069247bbb566afcaddac7bdd0
7、安装flannel插件
kubeclt apply -f kube-flannel.yml