文章目录

0、前景提要

  • master 节点需要的操作:

    • 更新 kube-apiserver 证书,将新增节点ip加入到证书内
  • node 节点需要的操作:
    • 部署 flanneldockerkubeletkube-proxy

1、准备node节点环境

1.0、修改配置脚本参数

  • 如果集群不是根据我的博客部署的,不需要进行这一步操作
  • 后面的操作,只需要在k8s-01节点上操作即可
k8s-01:~ # cd /opt/k8s/bin/
k8s-01:/opt/k8s/bin # vim k8s-env.sh
# 修改NODE_IPS为需要增加的node节点ip
export NODE_IPS=( 192.168.72.44 192.168.72.45 ) # 修改NODE_NAMES为需要增加的node节点主机名
export NODE_NAMES=( k8s-06 k8s-07 )

1.1、配置免密

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@${host}
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*Password*\" {send \"123.com\r\"; exp_continue}
\"*Password*\" {send \"123.com\r\";}
}"
done

1.2、添加hosts解析

k8s-01:~ # cat >> /etc/hosts <<EOF
> 192.168.72.44 k8s-06
> 192.168.72.45 k8s-07
> EOF
  • 分发到其他节点
#!/usr/bin/env bash

for host in k8s-02 k8s-03 k8s-04 k8s-05 k8s-06 k8s-07
do
printf "\e[1;34m${host}\e[0m\n"
scp /etc/hosts ${host}:/etc/hosts
done

1.3、修改主机名

#!/usr/bin/env bash

for host in 6 7
do
printf "\e[1;34mk8s-0${host}\e[0m\n"
ssh root@k8s-0${host} "hostnamectl set-hostname --static k8s-0${host}"
done

1.4、更新PATH变量

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "echo 'PATH=$PATH:/opt/k8s/bin' >> /etc/profile"
done

1.5、安装依赖包

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "zypper in -y ntp ipset iptables curl sysstat wget"
done

1.6、关闭防火墙以及swap分区

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "systemctl disable SuSEfirewall2.service --now"
ssh root@${host} "iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat"
ssh root@${host} "iptables -P FORWARD ACCEPT"
ssh root@${host} "swapoff -a"
ssh root@${host} "sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab"
done

1.7、开启内核模块

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "modprobe ip_vs_rr"
ssh root@${host} "modprobe br_netfilter"
ssh root@${host} "echo 'modprobe ip_vs_rr' >> /etc/rc.local"
ssh root@${host} "echo 'modprobe br_netfilter' >> /etc/rc.local"
ssh root@${host} "chmod +x /etc/rc.local"
done

1.8、内核优化

  • k8s-01节点上已经独立配置过k8s的内核优化文件,因此,直接scp过去,使配置生效即可
#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
scp /etc/sysctl.d/kubernetes.conf ${host}:/etc/sysctl.d/kubernetes.conf
ssh root@${host} "sysctl -p /etc/sysctl.d/kubernetes.conf"
done

1.9、创建部署所需目录

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "mkdir -p /opt/k8s/bin /etc/kubernetes/cert"
done

2、部署flannel网络

  • flannel需要配置的, 在一开始都已经就绪了,只需要分发文件,启动新节点的flannel服务即可

2.0、分发证书文件到新的节点

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "mkdir -p /etc/flanneld/cert"
scp /opt/k8s/ssl/ca.pem ${host}:/etc/kubernetes/cert/
scp /opt/k8s/ssl/flanneld*.pem ${host}:/etc/flanneld/cert/
scp /opt/k8s/packages/flannel/{flanneld,mk-docker-opts.sh} ${host}:/opt/k8s/bin/
scp /opt/k8s/conf/flanneld.service ${host}:/etc/systemd/system/
done

2.1、启动flanneld服务

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "systemctl daemon-reload && \
systemctl enable flanneld --now && \
systemctl status flanneld | grep Active"
done

2.2、查看新增node节点是否存在flannel网卡

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "ip a | grep flannel | grep -w inet"
done

3、部署docker

  • 同上,只需要分发文件,启动docker即可

3.0、分发文件到新的节点

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "mkdir /etc/docker"
scp /opt/k8s/packages/docker/* ${host}:/usr/bin/
scp /opt/k8s/conf/daemon.json ${host}:/etc/docker/
scp /opt/k8s/conf/docker.service ${host}:/etc/systemd/system/
done

3.1、启动docker服务

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "systemctl daemon-reload && \
systemctl enable docker --now && \
systemctl status docker | grep Active"
done

3.2、查看新节点的docker和flannel网卡是否为同一网段

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} 'ifconfig | egrep "docker*|flannel*" -A 1'
done

4、部署kubelet组件

4.0、创建kubelet bootstrap kubeconfig文件

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for node_name in ${NODE_NAMES[@]}
do
printf "\e[1;34m${node_name}\e[0m\n"
# 创建 token
export BOOTSTRAP_TOKEN=$(kubeadm token create \
--description kubelet-bootstrap-token \
--groups system:bootstrappers:${node_name} \
--kubeconfig ~/.kube/config) # 设置集群参数
kubectl config set-cluster kubernetes \
--certificate-authority=/etc/kubernetes/cert/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=/opt/k8s/ssl/kubelet-bootstrap-${node_name}.kubeconfig # 设置客户端认证参数
kubectl config set-credentials kubelet-bootstrap \
--token=${BOOTSTRAP_TOKEN} \
--kubeconfig=/opt/k8s/ssl/kubelet-bootstrap-${node_name}.kubeconfig # 设置上下文参数
kubectl config set-context default \
--cluster=kubernetes \
--user=kubelet-bootstrap \
--kubeconfig=/opt/k8s/ssl/kubelet-bootstrap-${node_name}.kubeconfig # 设置默认上下文
kubectl config use-context default --kubeconfig=/opt/k8s/ssl/kubelet-bootstrap-${node_name}.kubeconfig
done
"查看kubeadm为新节点创建的token"
k8s-01:/opt/k8s/ssl # kubeadm token list --kubeconfig ~/.kube/config
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
6sp12t.btr31aj1hc403tar 23h 2021-02-16T01:34:59+08:00 authentication,signing kubelet-bootstrap-token system:bootstrappers:k8s-06
bajiy9.b4fhfy8serfmyve0 23h 2021-02-16T01:35:00+08:00 authentication,signing kubelet-bootstrap-token system:bootstrappers:k8s-07

4.1、分发文件到新的节点

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for (( i=0; i < 2; i++ ))
do
sed -e "s/##NODE_IP##/${NODE_IPS[i]}/" /opt/k8s/conf/kubelet.service.template > \
/opt/k8s/conf/kubelet-${NODE_IPS[i]}.service
sed -e "s/##NODE_IP##/${NODE_IPS[i]}/" /opt/k8s/conf/kubelet-config.yaml.template > \
/opt/k8s/conf/kubelet-config-${NODE_IPS[i]}.yaml.template
done for node_name in ${NODE_NAMES[@]}
do
printf "\e[1;34m${node_name}\e[0m\n"
scp /opt/k8s/ssl/kubelet-bootstrap-${node_name}.kubeconfig \
${node_name}:/etc/kubernetes/cert/kubelet-bootstrap.kubeconfig
done for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
scp /opt/k8s/bin/kubelet ${host}:/opt/k8s/bin/kubelet
scp /opt/k8s/conf/kubelet-${host}.service ${host}:/etc/systemd/system/kubelet.service
scp /opt/k8s/conf/kubelet-config-${host}.yaml.template ${host}:/etc/kubernetes/kubelet-config.yaml
scp /opt/k8s/packages/pause.tar ${host}:/opt/k8s/
ssh root@${host} "docker load -i /opt/k8s/pause.tar"
done

4.2、启动kubelet服务

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "mkdir -p ${K8S_DIR}/kubelet/kubelet-plugins/volume/exec/"
ssh root@${host} "systemctl daemon-reload && \
systemctl enable kubelet --now && \
systemctl status kubelet | grep Active"
done

4.3、查看新增节点是否ready了

k8s-01:~ # kubectl get node
NAME STATUS ROLES AGE VERSION
192.168.72.39 Ready <none> 2d v1.19.7
192.168.72.40 Ready <none> 2d v1.19.7
192.168.72.41 Ready <none> 2d v1.19.7
192.168.72.42 Ready <none> 2d v1.19.7
192.168.72.43 Ready <none> 2d v1.19.7
192.168.72.44 Ready <none> 81s v1.19.7
192.168.72.45 Ready <none> 79s v1.19.7

4.4、手动approve server cert csr

k8s-01:~ # kubectl get csr | grep Pending | awk '{print $1}' | xargs kubectl certificate approve

5、部署kube-proxy

  • 同样,只需要分发文件后,启动kube-proxy即可

5.0、分发文件到新的节点

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for (( i=0; i < 2; i++ ))
do
sed -e "s/##NODE_IP##/${NODE_IPS[i]}/" /opt/k8s/conf/kube-proxy.service.template > \
/opt/k8s/conf/kube-proxy-${NODE_IPS[i]}.service
sed -e "s/##NODE_NAME##/${NODE_NAMES[i]}/" -e "s/##NODE_IP##/${NODE_IPS[i]}/" \
/opt/k8s/conf/kube-proxy-config.yaml.template > /opt/k8s/conf/kube-proxy-config-${NODE_IPS[i]}.yaml.template
done for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
scp /opt/k8s/ssl/kube-proxy.kubeconfig ${host}:/etc/kubernetes/cert
scp /opt/k8s/conf/kube-proxy-${host}.service ${host}:/etc/systemd/system/kube-proxy.service
scp /opt/k8s/conf/kube-proxy-config-${host}.yaml.template \
${host}:/etc/kubernetes/kube-proxy-config.yaml
scp /opt/k8s/packages/conntrack ${host}:/opt/k8s/bin/
scp /opt/k8s/packages/kubernetes/server/bin/kube-proxy ${host}:/opt/k8s/bin/
ssh root@${host} "chmod +x /opt/k8s/bin/*"
done

5.1、启动kube-proxy服务

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "mkdir -p ${K8S_DIR}/kube-proxy"
ssh root@${host} "modprobe ip_vs_rr"
ssh root@${host} "systemctl daemon-reload && \
systemctl enable kube-proxy --now && \
systemctl status kube-proxy | grep Active"
done

5.2、查看kube-proxy端口

#!/usr/bin/env bash
source /opt/k8s/bin/k8s-env.sh for host in ${NODE_IPS[@]}
do
printf "\e[1;34m${host}\e[0m\n"
ssh root@${host} "ss -nltp | grep kube-proxy"
done
  • 到此,kubernetes集群扩容结束

suse 12 二进制部署 Kubernetets 1.19.7 - 番外篇 - 增加node节点的更多相关文章

  1. suse 12 二进制部署 Kubernetets 1.19.7 - 第13章 - 部署metrics-server插件

    文章目录 1.13.0.创建metrics-server证书和私钥 1.13.1.生成metrics-server证书和私钥 1.13.2.开启kube-apiserver聚合配置 1.13.3.分发 ...

  2. suse 12 二进制部署 Kubernetets 1.19.7 - 第01章 - 创建CA证书和kubectl集群管理命令

    文章目录 1.kubernetes集群部署 1.0.创建CA证书和秘钥 1.0.0.安装cfssl工具 1.0.1.创建根证书 1.0.2.创建证书签名请求文件 1.0.3.生成CA证书和秘钥 1.0 ...

  3. suse 12 二进制部署 Kubernetets 1.19.7 - 第02章 - 部署etcd集群

    文章目录 1.2.部署etcd集群 1.2.0.下载etcd二进制文件 1.2.1.创建etcd证书和私钥 1.2.2.生成etcd证书和私钥 1.2.3.配置etcd为systemctl管理 1.2 ...

  4. suse 12 二进制部署 Kubernetets 1.19.7 - 第03章 - 部署flannel插件

    文章目录 1.3.部署flannel网络 1.3.0.下载flannel二进制文件 1.3.1.创建flannel证书和私钥 1.3.2.生成flannel证书和私钥 1.3.3.将pod网段写入et ...

  5. suse 12 二进制部署 Kubernetets 1.19.7 - 第04章 - 部署docker服务

    文章目录 1.4.部署docker 1.4.0.下载docker二进制文件 1.4.1.配置docker镜像加速 1.4.2.配置docker为systemctl管理 1.4.3.启动docker服务 ...

  6. suse 12 二进制部署 Kubernetets 1.19.7 - 第05章 - 部署kube-nginx

    文章目录 1.5.部署kube-nginx 1.5.0.下载nginx二进制文件 1.5.1.编译部署nginx 1.5.2.配置nginx.conf 1.5.3.配置nginx为systemctl管 ...

  7. suse 12 二进制部署 Kubernetets 1.19.7 - 第06章 - 部署kube-apiserver组件

    文章目录 1.6.部署kube-apiserver 1.6.0.创建kubernetes证书和私钥 1.6.1.生成kubernetes证书和私钥 1.6.2.创建metrics-server证书和私 ...

  8. suse 12 二进制部署 Kubernetets 1.19.7 - 第07章 - 部署kube-controller-manager组件

    文章目录 1.7.部署kube-controller-manager 1.7.0.创建kube-controller-manager请求证书 1.7.1.生成kube-controller-manag ...

  9. suse 12 二进制部署 Kubernetets 1.19.7 - 第08章 - 部署kube-scheduler组件

    文章目录 1.8.部署kube-scheduler 1.8.0.创建kube-scheduler请求证书 1.8.1.生成kube-scheduler证书和私钥 1.8.2.创建kube-schedu ...

随机推荐

  1. centos7 alias别名永久生效

    进入/etc/profile.d/目录 cd /etc/profile.d/ 在profile.d目录随意创建一个sh文件,例如alias_test.sh vi alias_test.sh##里面的内 ...

  2. vue实现引用less,sass全局变量

    1.npm install sass-resources-loader --save-dev: 2.build/utils.js中,修改 function resolveResource(name) ...

  3. Kubernetes最佳实践之腾讯云TKE 集群组建

    作者陈鹏,腾讯工程师,负责腾讯云 TKE 的售中.售后的技术支持,根据客户需求输出合理技术方案与最佳实践,为客户业务保驾护航.使用 TKE 来组建 Kubernetes 集群时,会面对各种配置选项,本 ...

  4. SSRF漏洞用到的其他协议(dict协议,file协议)

    0x00 引言 当SSRF打内网reids时,若gopher协议用不了,我们也可以用其他协议 0x01 dict协议一.定义:词典网络协议,在RFC 2009中进行描述.它的目标是超越Webster ...

  5. 【Java常用类】DateTimeFormatter

    DateTimeFormatter 方式一:预定义的标准格式 实例化 如:ISO_LOCAL_DATE_TIME;ISO_LOCAL_DATE;ISO_LOCAL_TIME DateTimeForma ...

  6. 论文解读GCN 1st《 Deep Embedding for CUnsupervisedlustering Analysis》

    论文信息 Tittle:<Spectral Networks and Locally Connected Networks on Graphs> Authors:Joan Bruna.Wo ...

  7. 网络编程-基于Websocket聊天室(IM)系统

    目录 一.HTML5 - Websocket协议 二.聊天室(IM)系统的设计 2.1.使用者眼中的聊天系统 2.2.开发者眼中的聊天系统 2.3.IM系统的特性 2.4.心跳机制:解决网络的不确定性 ...

  8. 【刷题-LeetCode】210. Course Schedule II

    Course Schedule II There are a total of n courses you have to take, labeled from 0 to n-1. Some cour ...

  9. 集合框架-Map重点方法entrySet演示

    1 package cn.itcast.p6.map.demo; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import ...

  10. netstat in Linux

    # netstat -unlt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address         ...