把master节点也加入到node节点中

IT
IT
IT
335
文章
1
评论
2020年9月12日13:42:52 评论 857 3271字阅读10分54秒

解压安装包

[root@k8s-master1 ~]# tar zxf kubernetes-node-linux-amd64.tar.gz

拷贝配置文件到指定目录

[root@k8s-master1 ~]# cp -a /root/kubernetes/node/bin/kubelet /opt/kubernetes/bin/
[root@k8s-master1 ~]# cp -a /root/kubernetes/node/bin/kube-proxy /opt/kubernetes/bin/

部署kubelet

  • 创建配置文件
[root@k8s-master1 ~]# 
cat > /opt/kubernetes/cfg/kubelet.conf << EOF
KUBELET_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--hostname-override=k8s-master1 \\
--network-plugin=cni \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--config=/opt/kubernetes/cfg/kubelet-config.yml \\
--cert-dir=/opt/kubernetes/ssl \\
--pod-infra-container-image=lizhenliang/pause-amd64:3.0"
EOF
  • –hostname-override:显示名称,集群中唯一
  • –network-plugin:启用CNI
  • –kubeconfig:空路径,会自动生成,后面用于连接apiserver
  • –bootstrap-kubeconfig:首次启动向apiserver申请证书
  • –config:配置参数文件
  • –cert-dir:kubelet证书生成目录
  • –pod-infra-container-image:管理Pod网络容器的镜像

配置参数文件

cat > /opt/kubernetes/cfg/kubelet-config.yml << EOF
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 0.0.0.0
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local 
failSwapOn: false
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 2m0s
    enabled: true
  x509:
    clientCAFile: /opt/kubernetes/ssl/ca.pem 
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 5m0s
    cacheUnauthorizedTTL: 30s
evictionHard:
  imagefs.available: 15%
  memory.available: 100Mi
  nodefs.available: 10%
  nodefs.inodesFree: 5%
maxOpenFiles: 1000000
maxPods: 110
EOF

拷贝已经生成的 kubelet bootstrap kubeconfig 配置文件

[root@k8s-node1 ~]# scp -r /opt/kubernetes/cfg/bootstrap.kubeconfig 10.10.1.37:/opt/kubernetes/cfg/

systemd管理kubelet

[root@k8s-master1 ~]#
cat > /usr/lib/systemd/system/kubelet.service << EOF
[Unit]
Description=Kubernetes Kubelet
After=docker.service
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kubelet.conf
ExecStart=/opt/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF

启动并设置开机启动

[root@k8s-master1 ~]# systemctl daemon-reload
[root@k8s-master1 ~]# systemctl start kubelet
[root@k8s-master1 ~]# systemctl enable kubelet

批准kubelet证书申请并加入集群

[root@k8s-master1 ~]# kubectl get csr
NAME AGE SIGNERNAME REQUESTOR CONDITION
node-csr-73i3ezAXElnfKMp6GZxOtgoBUsYTY3HhFboiiqrZa_s 33s kubernetes.io/kube-apiserver-client-kubelet kubelet-bootstrap Pending
[root@k8s-master1 ~]# kubectl certificate approve node-csr-73i3ezAXElnfKMp6GZxOtgoBUsYTY3HhFboiiqrZa_s 
certificatesigningrequest.certificates.k8s.io/node-csr-73i3ezAXElnfKMp6GZxOtgoBUsYTY3HhFboiiqrZa_s approved
[root@k8s-master1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-node1 Ready <none> 17h v1.18.5
k8s-node2 Ready <none> 17h v1.18.5
[root@k8s-master1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master1 NotReady <none> 6s v1.18.5
k8s-node1 Ready <none> 17h v1.18.5
k8s-node2 Ready <none> 17h v1.18.5

另外一台也按这样操作即可

[root@k8s-master2 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master1 NotReady <none> 4m21s v1.18.5
k8s-master2 NotReady <none> 48s v1.18.5
k8s-node1 Ready <none> 17h v1.18.5
k8s-node2 Ready <none> 17h v1.18.5

部署CNI网络

  • 同样的方法,创建目录和解压即可
[root@k8s-master1 ~]# mkdir -p /opt/cni/bin
[root@k8s-master1 ~]# tar zxvf cni-plugins-linux-amd64-v0.8.6.tgz -C /opt/cni/bin
  • 查看网络状态
[root@k8s-master1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready <none> 9m13s v1.18.5
k8s-master2 Ready <none> 5m40s v1.18.5
k8s-node1 Ready <none> 17h v1.18.5
k8s-node2 Ready <none> 17h v1.18.5
继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
ELK 最后更新:2020-9-27
IT
  • 本文由 发表于 2020年9月12日13:42:52
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Eureka服务剔除下线 ELK

Eureka服务剔除下线

格式 curl -X PUT "http://ip:port/eureka/apps/{application}/{instance}/status?value=OUT_OF_SERVICE" 示例 ...