集群新增主机:
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
root@op-admin1:/home/ tengfei
root@op-admin1:/home/ tengfei
vim /etc/hosts
添加:
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
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"
/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]
[root@fei-test-k8smaster1 ansible]
[root@fei-test-k8smaster1 ansible]
安装相关软件及目录创建
[root@fei-test-k8smaster1 ansible ]# ansible-playbook -i tmp.hosts 000.docker-kubelet-dir.yml
检查其他节点是否存在/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'
新增节点
运行 ./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
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
新增节点的有效检查
[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"
[root@fei-test-k8smaster1 ansible]
192 .168 .10 .159 Ready,SchedulingDisabled node 52 m v1 .14 .8
192 .168 .10 .45 Ready,SchedulingDisabled node 45 m v1 .14 .8
192 .168 .10 .58 Ready,SchedulingDisabled node 37 m v1 .14 .8
[root@fei-test-k8smaster1 ~ ]# calicoctl node status
[root@fei-test-k8smaster1 ~]
[root@fei-test-k8smaster1 ~]
[root@fei-test-k8smaster1 ~]
[root@fei-test-k8smaster1 ~]
[map[effect:NoSchedule key:key1 value:v1]]
[root@fei-test-k8smaster1 ~]
[map[effect:NoSchedule key:key1 value:v1]]
[root@fei-test-k8smaster1 ~]
[map[effect:NoSchedule key:key1 value:v1]]
[root@fei-test-k8smaster1 ~]
node/192.168 .10.45 untainted
[root@fei-test-k8smaster1 ~]
node/192.168 .10.159 untainted
[root@fei-test-k8smaster1 ~]
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
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"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了