运行node组件
首先我们需要在master上面生成一个角色用于node上证书绑定认证
在master上面操作(65)
创建认证用户
kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
将在master上面生成的 bootstrap.kubeconfig ,kube-proxy.kubeconfig文件传到master和node节点上面去
scp -P 10022 jyapp@10.50.182.65:/opt/kubernetes/cfg/*.kubeconfig .
在node上操作(10.50.182.66)
将我们需要的文件(kubelet ,kube-proxy)拿出来,文件都在我们下载的二进制包中,其中*.sh为我们自定义的脚本
[root@mail node_pkg]# ls
kubelet kubelet.sh kube-proxy proxy.sh
chmod +x *.sh
mv kubelet kube-proxy /opt/kubernetes/bin/
chmod +x /opt/kubernetes/bin/*
echo "export PATH=$PATH:/opt/kubernetes/bin" >> /etc/profile
安装kubelet
编辑安装脚本:
[root@mail node_pkg]# cat kubelet.sh
#!/bin/bash
NODE_ADDRESS=${1:-"10.50.182.66"}
DNS_SERVER_IP=${2:-"10.10.10.2"}
cat <<EOF >/opt/kubernetes/cfg/kubelet
KUBELET_OPTS="--logtostderr=true \\
--v=4 \\
--address=${NODE_ADDRESS} \\
--hostname-override=${NODE_ADDRESS} \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--experimental-bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--cert-dir=/opt/kubernetes/ssl \\
--allow-privileged=true \\
--cluster-dns=${DNS_SERVER_IP} \\
--cluster-domain=cluster.local \\
--fail-swap-on=false \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
EOF
cat <<EOF >/usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service
[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kubelet
ExecStart=/opt/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kubelet
systemctl restart kubelet
执行脚本安装,日志/var/log/message:
./kubelet.sh 10.50.182.66 10.10.10.2
安装kube-proxy:
编写安装脚本:
[root@mail node_pkg]# cat proxy.sh
#!/bin/bash
NODE_ADDRESS=${1:-"10.50.182.66"}
cat <<EOF >/opt/kubernetes/cfg/kube-proxy
KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--hostname-override=${NODE_ADDRESS} \
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig"
EOF
cat <<EOF >/usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-proxy
ExecStart=/opt/kubernetes/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kube-proxy
systemctl restart kube-proxy
启动脚本:
./proxy.sh 10.50.182.66
ps aux |grep proxy
报错查看:/var/log/message
journalctl -f -t kube-proxy
journalctl -u kube-proxy
查询集群状态:
[root@localhost ~]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-0EfKRr3ZU_UVFi5O8XLASGNxTzMrIsxMHg8oHJnY3JA 4m kubelet-bootstrap Pending
node-csr-MTGLph0ohPwDJK6FtjJagnkjo3utvYjL1N52nBA1xRU 43m kubelet-bootstrap Pending
目前没有节点加入,我们将节点加入:
kubectl certificate approve node-csr-0EfKRr3ZU_UVFi5O8XLASGNxTzMrIsxMHg8oHJnY3JA
kubectl certificate approve node-csr-MTGLph0ohPwDJK6FtjJagnkjo3utvYjL1N52nBA1xRU
执行这条命令之后,会在node生成一个kubeconfig文件