首页 > 其他分享 >k8s扩容节点

k8s扩容节点

时间:2022-10-03 01:11:57浏览次数:49  
标签:扩容 192.168 fei ansible hosts test k8s root 节点

集群新增主机:
192.168.10.45 fei-test-k8snode12.idc2.test.cn
192.168.10.159 fei-test-k8snode13.idc2.test.cn
192.168.10.58 fei-test-k8snode14.idc2.test.cn
 
ssh 192.168.10.19
ansible主机添加(master1操作)

准备阶段

  • 互信操作
借助于中控机拷贝id_rsa.pub到新增机器的authorized_keys并进行测试,登录op-admin1.idc1主机做互信
将master1的id_rsa.pub文件copy到新增节点:
ssh-copy-id -i /home/tengfei/florence/id_rsa.pub $ip;【$ip 是新加的主机 ip,以下不再说明】
=>
root@op-admin1:/home/tengfei# ssh-copy-id -i /home/tengfei/florence/id_rsa.pub 192.168.10.45
root@op-admin1:/home/tengfei# ssh-copy-id -i /home/tengfei/florence/id_rsa.pub 192.168.10.159
root@op-admin1:/home/tengfei# ssh-copy-id -i /home/tengfei/florence/id_rsa.pub 192.168.10.58
  • 添加新增worker到hosts中
vim /etc/hosts
添加:
#new worker 2021/05/24
192.168.10.45 fei-test-k8snode12.idc2.test.cn n12
192.168.10.159 fei-test-k8snode13.idc2.test.cn n13
192.168.10.58 fei-test-k8snode14.idc2.test.cn n14
  • 将新增节点写到一个临时的host文件中:tmp.hosts
cd /etc/ansible
cat tmp.hosts
192.168.10.45
192.168.10.159
192.168.10.58
  • 新增节点与现有k8s节点与时间服务器同步时间:
cd /etc/ansible
ansible -i tmp.hosts all -m shell -a  "ntpdate 192.168.4.12 192.168.4.21"
ansible -i all.hosts all_k8s_node -m shell -a "ntpdate 192.168.4.12 192.168.4.21"
  • 查看时间:
ansible -i tmp.hosts all -m shell -a  "w"
ansible -i all.hosts all_k8s_node -m shell -a "w"
cat /etc/cron.d/sys_init_cron
 ntpdate 192.168.4.12 192.168.4.21
  • 从master1节点上面copy hosts同步到新增节点上面
ansible -i tmp.hosts all -m copy -a "src=/etc/hosts dest=/etc/hosts"
  • check dns本地解析配置:
/etc/resolv.conf的dns绑定(在新增服务器上操作)
并测试 curl http://nexus.intra.test.cn
  • 升级内核(互医不是必须操作的)
ansible -i tmp.hosts all -m shell -a "yum update kernel -y"
ansible -i tmp.hosts all -m shell -a "reboot"

删除相关旧文件

如:mesos/marathon/docker 等服务
[root@fei-test-k8smaster1 ansible]# ansible-playbook -i tmp.hosts 危险操作.yml  --list-host   #确认操作主机ip
[root@fei-test-k8smaster1 ansible]# ansible-playbook -i tmp.hosts 危险操作.yml
[root@fei-test-k8smaster1 ansible]# kubectl get pod --all-namespaces  | grep -v Run

安装相关软件及目录创建

  • 安装相关软件
[root@fei-test-k8smaster1 ansible]# ansible-playbook -i tmp.hosts 000.docker-kubelet-dir.yml
  • 检查kubelet的配置
检查其他节点是否存在/var/lib/kubelet/config.json
若有则同步后重启新增节点的kubelet以刷取配置
  • 创建各个节点额外的目录
[root@fei-test-k8smaster1 ansible]# ansible -i tmp.hosts all -m shell -a 'mkdir -p /home/work/eventlog/statslog'

新增节点

  • master1 节点上
运行 ./easzctl add-node $ip 将节点加入集群;多个节点,依次执行即可;($ip 为节点 ip 地址)
cd /etc/ansible/tools
for x in ` cat ../tmp.hosts`;do  bash easzctl add-node $x && kubectl cordon $x;done
  • 镜像载入
在master1节点上:
ansible-playbook -i tmp.hosts  03.load-images.yml
  • 同步docker的配置文件
ansible -i tmp.hosts all -m copy -a "src=/etc/docker/daemon.json dest=/etc/docker/daemon.json"
ansible -i tmp.hosts all -m shell -a 'kill -HUP `pidof dockerd`'
  • 删除多余网卡
add-node 后会在新加入的节点中默认初始化一个mynet0网卡,需要手工删除,才能正常启动calico
ip link list
ip link del mynet0
ansible -i tmp.hosts all -m shell -a 'ip link list|grep mynet0'
ansible -i tmp.hosts all -m shell -a 'ip link del mynet0'
  • 移除新增节点上 kubectl 的配置文件 /root/.kube/config
ansible -i tmp.hosts all -m shell -a "ls /root/.kube/config && rm -rf  /root/.kube/config"
  • 重载 journald和docker(此步骤可忽略)
ansible-playbook -i tmp.hosts 08.reload-journald.yml

新增节点的有效检查

  • 所有pod健康
[root@fei-test-k8smaster1 tools]# kubectl get po --all-namespaces |egrep -Ev "Run|es-index"
[root@fei-test-k8smaster1 ansible]# kubectl get po -A -owide|egrep "22.159|22.58|22.45"
  • 所有node ready
[root@fei-test-k8smaster1 ansible]# kubectl get node|egrep "22.159|22.58|22.45"
192.168.10.159   Ready,SchedulingDisabled   node     52m    v1.14.8
192.168.10.45    Ready,SchedulingDisabled   node     45m    v1.14.8
192.168.10.58    Ready,SchedulingDisabled   node     37m    v1.14.8
  • 验证扩容节点的网络连通性
[root@fei-test-k8smaster1 ~]# calicoctl node status
  • 设置污点
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.45 key1=v1:NoSchedule
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.159 key1=v1:NoSchedule
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.58 key1=v1:NoSchedule
  • 查看污点配置
[root@fei-test-k8smaster1 ~]# kubectl get nodes 192.168.10.45 -o go-template={{.spec.taints}}
[map[effect:NoSchedule key:key1 value:v1]]
[root@fei-test-k8smaster1 ~]# kubectl get nodes 192.168.10.159 -o go-template={{.spec.taints}}
[map[effect:NoSchedule key:key1 value:v1]]
[root@fei-test-k8smaster1 ~]# kubectl get nodes 192.168.10.58 -o go-template={{.spec.taints}}
[map[effect:NoSchedule key:key1 value:v1]]
  • 撤销污点配置
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.45 key1:-
node/192.168.10.45 untainted
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.159 key1:-
node/192.168.10.159 untainted
[root@fei-test-k8smaster1 ~]# kubectl taint nodes 192.168.10.58 key1:-
node/192.168.10.58 untainted
  • 取消禁止调度限制
[root@fei-test-k8smaster1 ~]# kubectl uncordon 192.168.10.45
[root@fei-test-k8smaster1 ~]# kubectl uncordon 192.168.10.159
[root@fei-test-k8smaster1 ~]# kubectl uncordon 192.168.10.58
  • mynet0是否删除
ip link show | grep mynet0
  • 镜像拉取是否正常
[root@fei-test-k8smaster1 ansible]# docker save quay.io/prometheus/node-exporter:v0.18.1 -o /tmp/node-exporter.tar
[root@fei-test-k8smaster1 ansible]# docker save quay.io/coreos/kube-rbac-proxy:v0.4.1 -o /tmp/kube-rbac-proxy.tar
[root@fei-test-k8smaster1 ansible]# ansible -i tmp.hosts all -m  shell -a "docker load < /tmp/kube-rbac-proxy.tar"
[root@fei-test-k8smaster1 ansible]# ansible -i tmp.hosts all -m  shell -a "docker load < /tmp/node-exporter.tar"

标签:扩容,192.168,fei,ansible,hosts,test,k8s,root,节点
From: https://www.cnblogs.com/tengfei520/p/16749864.html

相关文章

  • K8S日常操作手册
    kubectl创建对象创建资源$kubectlcreate-f./my-manifest.yaml使用多个文件创建资源$kubectlcreate-f./my1.yaml-f./my2.yaml使用目录下的所有清单文件(yam......
  • K8S缩容
    如果你想从Kubernetes集群中删除节点,正确流程如下:1、获取节点列表kubectlgetnode2、设置不可调度kubectlcordon$node_name3、驱逐节点上的Podkubectldrain$n......
  • Mysql function 自定义函数,查找子节点
    ThisfunctionhasnoneofDETERMINISTIC,NOSQL,orREADSSQLDATAinitsdeclarationandbinaryloggingisenabled(you*might*wanttousethelesssafelog_......
  • 【K8S】Kubernetes控制器Controller-RS/Deployment/HPA详解
    一、介绍Pod是kubernetes的最⼩管理单元,在kubernetes中,按照pod的创建方式可以将其分为两类:自主式pod:kubernetes直接创建出来的Pod,这种pod删除后就没有了,也不会重建......
  • 【Golang】关于Golang中Slice扩容策略
    一、概述当切片的容量不足时,我们会调用runtime.growslice函数为切片扩容,扩容是为切片分配新的内存空间并拷贝原切片中元素的过程,我们先来看新切片的容量是如何确定的,使......
  • 【微电网优化】基于粒子群实现IEEE33节点配电网系统中接入5个微电网的最优注入功率优
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • VMware中Ubuntu扩容
    https://blog.csdn.net/weixin_47306605/article/details/121727192?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Ra......
  • AD节点监视器之TCP半连接
    今天创建应用负载的时候,关注了一下节点监视器的类型<ignore_js_op>监视器的类型很多,这里的TCP半连接是什么意思呢,在这里简单的分析一下,不对的地方请各位大神批评指正......
  • 【云原生】Hive on k8s 环境部署
    目录一、概述二、开始部署1)构建镜像2)添加Metastore服务编排1、配置2、控制器3、Service3)添加HiveServer2服务编排1、控制器2、Service4)修改values.yaml5)开始部署6)测试......
  • k8s helm方式部署夜莺监控系统
    一、夜莺介绍   Nightingale|夜莺监控,一款先进的开源云原生监控分析系统,采用All-In-One的设计,集数据采集、可视化、监控告警、数据分析于一体,与云原生生态紧密......