|NO.Z.00033|——————————|^^ 部署 ^^|——|Kubernetes&高可用集群.V07|——|Node扩容|

一、加入Kubernetes Node
### --- 在node1上执行
~~~     向集群添加新节点,执行在kubeadm init输出的kubeadm join命令:

[root@k8s-node1 ~]# kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 --discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
### --- **集群网络重新安装,因为添加了新的node节点**

[root@k8s-master2 flannel]# kubectl get node
NAME          STATUS     ROLES    AGE    VERSION
k8s-master1   Ready      master   14m    v1.16.3
k8s-master2   Ready      master   41m    v1.16.3
k8s-node1     NotReady   <none>   115s   v1.16.3
### --- 检查状态

[root@k8s-master2 flannel]# kubectl get pods --all-namespaces
kube-system   kube-flannel-ds-6srvr                 0/1     Init:0/1   0          10s
kube-system   kube-flannel-ds-c48zg                 1/1     Running    0          10s
kube-system   kube-flannel-ds-hld8w                 1/1     Running    0          10s
### --- 因为新添加了node节点,所以重新部署一下网络

[root@k8s-master2 flannel]# kubectl delete -f kube-flannel.yml 
podsecuritypolicy.policy "psp.flannel.unprivileged" deleted
clusterrole.rbac.authorization.k8s.io "flannel" deleted
clusterrolebinding.rbac.authorization.k8s.io "flannel" deleted
serviceaccount "flannel" deleted
configmap "kube-flannel-cfg" deleted
daemonset.apps "kube-flannel-ds" deleted
[root@k8s-master2 flannel]# kubectl apply -f kube-flannel.yml 
### --- 检查状态:都是ready状态说明加入OK

NAME          STATUS   ROLES    AGE    VERSION
k8s-master1   Ready    master   19m    v1.16.3
k8s-master2   Ready    master   46m    v1.16.3
k8s-node1     Ready    <none>   7m4s   v1.16.3
[root@k8s-master2 flannel]# kubectl get pods --all-namespaces
kube-system   kube-flannel-ds-6srvr                 1/1     Running   0          2m11s
kube-system   kube-flannel-ds-c48zg                 1/1     Running   0          2m11s
kube-system   kube-flannel-ds-hld8w                 1/1     Running   0          2m11s
kube-system   kube-proxy-4pp2x                      1/1     Running   0          6m29s
二、测试kubernetes集群
### --- 在Kubernetes集群中创建一个pod,验证是否正常运行:

[root@k8s-master1 ~]# kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
[root@k8s-master1 ~]# kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort
service/nginx exposed
[root@k8s-master1 ~]# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-86c57db685-hfzcg   1/1     Running   0          44s
 
[root@k8s-master1 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.1.0.1      <none>        443/TCP        52m
nginx        NodePort    10.1.15.138   <none>        80:30168/TCP   19s
### --- 访问地址:http://NodeIP:Port 

~~~     http://10.10.10.11:30168/   输出:Welcome to nginx!
~~~     http://10.10.10.12:30168/   输出:Welcome to nginx!
~~~     http://10.10.10.13:30168/   输出:Welcome to nginx!
### --- 通过虚拟IP访问也是可以访问到的,此刻任何一个master节点节点宕机,都可正常输出,

~~~     http://10.10.10.15:30168/   输出:Welcome to nginx!    

附录一:
### --- 报错现象:

[root@k8s-node1 ~]# kubeadm join master.k8s.io:16443 --token 6npcq0.ps39u2hwjaae0g31 --discovery-token-ca-cert-hash sha256:706cb8d93f25dc82e127a6fcf86c6ab27971ee5830659977c0ec0e5171db101e
[preflight] Running pre-flight checks
    [WARNING Hostname]: hostname "k8s-node1" could not be reached
    [WARNING Hostname]: hostname "k8s-node1": lookup k8s-node1 on 114.114.114.114:53: no such host
### --- 解决方案:

[root@k8s-node1 ~]# cat /etc/hosts
10.10.10.15    master.k8s.io   k8s-vip
10.10.10.11    master01.k8s.io k8s-master1
10.10.10.12    master02.k8s.io k8s-master2
10.10.10.13    node01.k8s.io   k8s-node1

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(27)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示