k8s节点扩容与缩容

news/2024/11/7 18:42:25/
#使用镜像:ikubernetes/myapp:v1 1个master节点2个node节点
[root@master ~]# kubectl get nodes -o wide
NAME     STATUS   ROLES    AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
master   Ready    master   66d   v1.13.4   192.168.100.2   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
node01   Ready    <none>   66d   v1.13.4   192.168.100.3   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
node02   Ready    <none>   64d   v1.13.4   192.168.100.4   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
#pod的副本数为3副本,node1和node2节点都有应用分布
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE    IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-4kclm   1/1     Running   0          12s    10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          108s   10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-r86h8   1/1     Running   0          103s   10.244.1.72    node01   <none>           <none>
#缩容--cordon使节点不可调用,不影响现有pod的节点分布,新增pod将会调度至其他节点
[root@master ~]# kubectl cordon node02 
node/node02 cordoned
[root@master ~]# kubectl get nodes
NAME     STATUS                     ROLES    AGE   VERSION
master   Ready                      master   66d   v1.13.4
node01   Ready                      <none>   66d   v1.13.4
node02   Ready,SchedulingDisabled   <none>   64d   v1.13.4
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-4kclm   1/1     Running   0          7m14s   10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          8m50s   10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-r86h8   1/1     Running   0          8m45s   10.244.1.72    node01   <none>           <none>
#通过增加pod的副本数验证新增pod的节点分布
[root@master ~]# kubectl scale deploy/myapp  --replicas=5 -n myspace
deployment.extensions/myapp scaled
#最后2个为新增app的分布(根据时间)
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-4kclm   1/1     Running   0          8m59s   10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          10m     10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-r86h8   1/1     Running   0          10m     10.244.1.72    node01   <none>           <none>
myapp-55b9654fbb-s9hl9   1/1     Running   0          13s     10.244.1.73    node01   <none>           <none>
myapp-55b9654fbb-t9ntv   1/1     Running   0          13s     10.244.1.74    node01   <none>           <none>
#恢复node2节点至可调度
[root@master ~]# kubectl uncordon node02
node/node02 uncordoned
[root@master ~]# kubectl get nodes -o wide
NAME     STATUS   ROLES    AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
master   Ready    master   66d   v1.13.4   192.168.100.2   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
node01   Ready    <none>   66d   v1.13.4   192.168.100.3   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
node02   Ready    <none>   64d   v1.13.4   192.168.100.4   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://1.13.1
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-4kclm   1/1     Running   0          23m   10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          24m   10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-r86h8   1/1     Running   0          24m   10.244.1.72    node01   <none>           <none>
myapp-55b9654fbb-s9hl9   1/1     Running   0          14m   10.244.1.73    node01   <none>           <none>
myapp-55b9654fbb-t9ntv   1/1     Running   0          14m   10.244.1.74    node01   <none>           <none>
#缩容--drain不仅不可以调用,还会drain(排干)节点上的pod,使该节点上的pod资源调度至其他节点
#当前的pods分布
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-4kclm   1/1     Running   0          23m   10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          24m   10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-r86h8   1/1     Running   0          24m   10.244.1.72    node01   <none>           <none>
myapp-55b9654fbb-s9hl9   1/1     Running   0          14m   10.244.1.73    node01   <none>           <none>
myapp-55b9654fbb-t9ntv   1/1     Running   0          14m   10.244.1.74    node01   <none>           <none>
#让node01节点不可调用,--ignore-daemonset忽略节点由守护进程控管的应用,有3个pod被evicted(脱离)
[root@master ~]# kubectl drain node01 --ignore-daemonsets  
node/node01 already cordoned
WARNING: Ignoring DaemonSet-managed pods: default-http-backend-xkwzx, kube-flannel-ds-amd64-967jn, kube-proxy-zc8vh
pod/myapp-55b9654fbb-t9ntv evicted
pod/nginx-ingress-controller-65795b86d-wrrt7 evicted
pod/myapp-55b9654fbb-r86h8 evicted
pod/myapp-55b9654fbb-s9hl9 evicted
node/node01 evicted
#如下输出表明有3个位于node01节点的pod转移到了node02上
[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-2hkzz   1/1     Running   0          3m47s   10.244.2.202   node02   <none>           <none>
myapp-55b9654fbb-4kclm   1/1     Running   0          35m     10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          37m     10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-kdhtp   1/1     Running   0          3m48s   10.244.2.200   node02   <none>           <none>
myapp-55b9654fbb-qvxvq   1/1     Running   0          3m47s   10.244.2.201   node02   <none>           <none>
#扩容pod副本验证新的pod也不会部署到node01节点,此时就可以离线node01节点
[root@master ~]# kubectl scale deploy/myapp --replicas=10 -n myspace
deployment.extensions/myapp scaled[root@master ~]# kubectl get pods -n myspace -o wide
NAME                     READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
myapp-55b9654fbb-2hkzz   1/1     Running   0          7m57s   10.244.2.202   node02   <none>           <none>
myapp-55b9654fbb-4kclm   1/1     Running   0          39m     10.244.2.199   node02   <none>           <none>
myapp-55b9654fbb-5nqvf   1/1     Running   0          41m     10.244.2.198   node02   <none>           <none>
myapp-55b9654fbb-8qdf5   1/1     Running   0          18s     10.244.2.206   node02   <none>           <none>
myapp-55b9654fbb-92pnr   1/1     Running   0          18s     10.244.2.205   node02   <none>           <none>
myapp-55b9654fbb-jkgpq   1/1     Running   0          18s     10.244.2.204   node02   <none>           <none>
myapp-55b9654fbb-kdhtp   1/1     Running   0          7m58s   10.244.2.200   node02   <none>           <none>
myapp-55b9654fbb-mhklw   1/1     Running   0          18s     10.244.2.208   node02   <none>           <none>
myapp-55b9654fbb-nq44t   1/1     Running   0          18s     10.244.2.207   node02   <none>           <none>
myapp-55b9654fbb-qvxvq   1/1     Running   0          7m57s   10.244.2.201   node02   <none>           <none>
#扩容--前提基础软件准备就绪,docker,flannel,kube-proxy,kubelet,coredns等准备就绪
[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES    AGE     VERSION
master   Ready    master   3h56m   v1.13.4
node01   Ready    <none>   3h53m   v1.13.4
#当前的token已经无效超过了24个小时
[root@master ~]# kubeadm token list
TOKEN                     TTL         EXPIRES                     USAGES                   DESCRIPTION                                                EXTRA GROUPS
05txgd.zd1kd5avee64leiv   <invalid>   2020-04-01T12:52:32+08:00   authentication,signing   The default bootstrap token generated by 'kubeadm init'.   system:bootstrappers:kubeadm:default-node-token
#创建新的token,TTL为23小时
[root@master ~]# kubeadm token create
avvx3t.1rb388d69211v42e
[root@master ~]# kubeadm  token list
TOKEN                     TTL         EXPIRES                     USAGES                   DESCRIPTION                                                EXTRA GROUPS
05txgd.zd1kd5avee64leiv   <invalid>   2020-04-01T12:52:32+08:00   authentication,signing   The default bootstrap token generated by 'kubeadm init'.   system:bootstrappers:kubeadm:default-node-token
avvx3t.1rb388d69211v42e   23h         2020-06-09T09:27:10+08:00   authentication,signing   <none>                                                     system:bootstrappers:kubeadm:default-node-token
#查看hash
[root@master ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
dbd5573750f525e3d7ffdf03fc9436c63e1901c590589fadbb3f9e98feae480f
#新增节点执行(node02)
[root@node02 ~]#  kubeadm join 192.168.100.2:6443 --token avvx3t.1rb388d69211v42e --discovery-token-ca-cert-hash sha256:dbd5573750f525e3d7ffdf03fc9436c63e1901c590589fadbb3f9e98feae480f --ignore-preflight-errors=Swap
[preflight] Running pre-flight checks[WARNING Swap]: running with swap on is not supported. Please disable swap
[discovery] Trying to connect to API Server "192.168.100.2:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.100.2:6443"
[discovery] Requesting info from "https://192.168.100.2:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.100.2:6443"
[discovery] Successfully established connection with API Server "192.168.100.2:6443"
[join] Reading configuration from the cluster...
[join] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.13" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node02" as an annotationThis 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 master to see this node join the cluster.
#新增节点成功加入
[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES    AGE     VERSION
master   Ready    master   68d     v1.13.4
node01   Ready    <none>   68d     v1.13.4
node02   Ready    <none>   2m19s   v1.13.4
总结:
扩容:新增节点的基础软件包准备好,并成功运行起来加入集群主要用到kubeadm join ,hash值和token
缩容:kubectl drain node ,使该节点不可调用,排干并驱逐现有节点的pod资源,并调度至其他节点

http://www.ppmy.cn/news/180428.html

相关文章

全志V3S Linux 开发过程回记

半年没有碰linux了&#xff0c;一直在玩ESP32&#xff0c;把esp32的人脸识别、语音识别、百度AI识别都摸了个遍 &#xff0c;搞完这些开源出来后&#xff0c;竟然没人喜欢&#xff0c;瞬间就觉得没意思 于是&#xff0c;重新捡起linux开发&#xff0c;我是从全志V3S入门&#x…

荔枝派 zero(全志V3S)-编译及SD烧录

之前买了个荔枝派&#xff0c;全志的A3S芯片。折腾了两天&#xff0c;写一下编译和SD烧录的过程。 目录 1.直接烧录镜像文件 2.uboot编译 3.kernel编译 4.rootfs编译 5.烧录 6.串口登录 1.直接烧录镜像文件 百度到了一堆的资料&#xff0c;下面是网盘链接 链接&#x…

电网电压及中国TN-S系统学习

目前各国的室内电压大体分为两种&#xff1a;100V~130V&#xff0c;220V~240V两个类型。 100V、110V~130V被归类低压&#xff0c;如美国、日本等以及船上的电压&#xff0c;注重安全&#xff1b;220V~240V被称为高压&#xff0c;其中包括中国的220伏及英国的230伏和很多欧洲国…

k8s(三)、kube-router: K8S BGP直通网络CNI方案

前言 上一篇讲到&#xff0c;k8s使用traefik代理集群内部服务&#xff0c;灵活地注入代理配置的方式&#xff0c;提供7层对外服务&#xff08;参考&#xff1a;k8s&#xff08;二&#xff09;、对外服务&#xff09;。在本篇&#xff0c;使用kube-router的cni&#xff0c;实现…

RISC-V (CH32V103)与Cortex-M3内核(CH32F103)单片机中断延时测评

最近在学习RISC-V架构的MCU&#xff0c;特地学习了一下“中断处理机制”&#xff0c;对比之前使用过的Cortex-M3内核单片机&#xff0c;研究它们在中断执行和处理上的差异和效率。 样品选择 CH32V103C8T6和CH32F103C8T6 CH32V103C8T6&#xff0c;沁恒微电子的RSIC-V架构32位…

彩色MT9V034摄像头 Bayer转rgb FPGA实现

彩色MT9V034摄像头 Bayer转rgb FPGA实现 1 图像bayer格式介绍 bayer格式是伊士曼柯达公司科学家Bryce Bayer发明的&#xff0c;Bryce Bayer所发明的拜耳阵列被广泛运用数字图像。Bayer格式是相机内部的原始数据, 一般后缀名为.raw。 对于彩色图像,一般是三原色数据&#xff0c…

AIC, BIC v.s. Crossvalidation

模型选择的方法有许多&#xff0c;例如 AIC, BIC, Crossvalidation, GCV等等。这 些准则的适用条件有哪些&#xff1f;该如何选择不同的准则&#xff1f; AIC, BIC准则 ref&#xff1a;https://methodology.psu.edu/node/504 ref&#xff1a;https://en.wikipedia.org/wiki/B…

v3S编译大全(uboot 主线linux buildroot)

文章目录 一、github代理下载二、Uboot1.uboot下载2.uboot的基本结构3.uboot配置屏幕4.修改可以从tf卡启动5.配置6.编译6.烧录测试1.进入 fel 模式使用 sunxi-fel 工具烧录1.基本命令2.有两种方式进行程序下载&#xff1a; 2.烧录到TF/SD卡 7.uboot启动信息 三、主线linxu编译与…