### 4.1.配置免密码登录node节点,按回车生产rsa
#ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa.pub'
for NODE in node1 node2; do
#配置免密码登录node,可去除
# ssh ${NODE} "mkdir -p /root/.ssh/"
# scp /root/.ssh/id_rsa.pub root@${NODE}:/root/.ssh/authorized_keys
ssh ${NODE} "mkdir -p /etc/kubernetes/pki/"
ssh ${NODE} "mkdir -p /etc/etcd/ssl"
# Etcd ca and cert
for FILE in etcd-ca.pem etcd.pem etcd-key.pem; do
scp /etc/etcd/ssl/${FILE} ${NODE}:/etc/etcd/ssl/${FILE}
done
# Kubernetes ca and cert
for FILE in pki/ca.pem pki/ca-key.pem bootstrap.conf kubelet.conf; do
scp /etc/kubernetes/${FILE} ${NODE}:/etc/kubernetes/${FILE}
done
done
### 4.2.配置node
## 1.下载kubelet组件
## Download Kubernetes
cp /data/download/kubelet /usr/local/bin/kubelet
cp /data/download/kubectl /usr/local/bin/kubectl
chmod +x /usr/local/bin/kubelet
chmod +x /usr/local/bin/kubectl
## 2.Download CNI
mkdir -p /opt/cni/bin
cd /opt/cni/bin
cp /data/download/cni-plugins-amd64-v0.6.0.tgz /opt/cni/bin/cni-plugins-amd64-v0.6.0.tgz
tar -zxvf cni-plugins-amd64-v0.6.0.tgz
## 3.下载kubelet.service相关文件来管理 kubelet:(10-kubelet.conf与master不一样)
mkdir -p /etc/systemd/system/kubelet.service.d
cp /data/download/kubelet.service /lib/systemd/system/kubelet.service
cp /data/download/10-kubelet-node.conf /etc/systemd/system/kubelet.service.d/10-kubelet.conf
## 4.接着在所有node创建 var 存放信息,然后启动 kubelet 服务:
mkdir -p /var/lib/kubelet /var/log/kubernetes /etc/kubernetes/manifests
systemctl enable kubelet.service && systemctl start kubelet.service
### 4.3.授权 Kubernetes Node
## 1.当所有节点都完成后,在master节点,因为我们采用 TLS Bootstrapping,所需要创建一个 ClusterRoleBinding
kubectl create clusterrolebinding kubelet-bootstrap \
--clusterrole=system:node-bootstrapper \
--user=kubelet-bootstrap
kubectl get no
kubectl get csr
## 2.允许节点加入集群:
kubectl get csr | awk '/Pending/ {print $1}' | xargs kubectl certificate approve
kubectl get csr
kubectl get no