3

基于Kubernetes v1.24.0的集群搭建(二) - 艾心❤

 1 year ago
source link: https://www.cnblogs.com/edison0621/p/16378304.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

上一篇文章主要是介绍了,每台虚拟机的环境配置。接下来我们开始有关K8S的相关部署。

另外补充一下上一篇文章中的K8S的change​log链接:

https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.24.md

1 配置yum源

所有节点都需要执行此操作

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

533598-20220615145031269-642031970.png

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
533598-20220615145031852-354277070.png
yum clean all
533598-20220615145033301-1883370812.png
yum makecache
533598-20220615145033964-624176414.png

2 br_netfilter和ip_conntrack模块配置

  • 所有节点都需要执行此操作
  • 加载 br_netfilter 模块以启用内核 ipv4 转发,1.20+强依赖该模块
  • ip_conntrack 模块来记录iptables 网络包的状态,并把每条记录保存到table 里
modprobe br_netfilter
modprobe ip_conntrack

这里为了防止bridge-nf-call-ip6tables和bridge-nf-call-iptables无法启动,需要配置br_netfilter开机自动启动。

  1. 新建 /etc/rc.sysinit 文件
cat >>/etc/rc.sysinit<<EOF
#!/bin/bash
for file in /etc/sysconfig/modules/*.modules ; do
[ -x $file ] && $file
done
EOF
533598-20220615145034468-700916941.png

2. 新建br_netfilter.modules和ip_conntrack.modules

echo "modprobe br_netfilter" >/etc/sysconfig/modules/br_netfilter.modules
echo "modprobe ip_conntrack" >/etc/sysconfig/modules/ip_conntrack.modules

533598-20220615145034896-874017093.png

3 配置内核转发及网桥过滤

添加网桥过滤及内核转发配置文件

cat <<EOF >/etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness=0
EOF
533598-20220615145035959-976311629.png

net.bridge.bridge-nf-call-ip6tables:是否在 ip6tables 链中过滤 IPv6 包

net.bridge.bridge-nf-call-iptables:是否在 iptables 链中过滤 IPv4 包

执行如下命令,使配置生效

$ sysctl -p /etc/sysctl.d/k8s.conf 

4 安装ipset及ipvs

所有主机都需要操作

4.1 安装ipset

ipset是iptables的扩展,它允许你创建匹配整个地址集合的规则。而不像普通的iptables链只能单IP匹配, ip集合存储在带索引的数据结构中,这种结构即时集合比较大也可以进行高效的查找,除了一些常用的情况,比如阻止一些危险主机访问本机,从而减少系统资源占用或网络拥塞,IPsets也具备一些新防火墙设计方法,并简化了配置。

yum install ipset -y
533598-20220615145036447-450238351.png

4.2 安装ipvs

IPVS (IP Virtual Server)是基于Netfilter的、作为linux内核的一部分实现传输层负载均衡的技术。

IPVS集成在LVS(Linux Virtual Server)中,它在主机中运行,并在真实服务器集群前充当负载均衡器。IPVS可以将对TCP/UDP服务的请求转发给后端的真实服务器,因此IPVS天然支持Kubernetes Service。

随着kubernetes使用量的增长,其资源的可扩展性变得越来越重要。特别是对于使用kubernetes运行大型工作负载的开发人员或者公司来说,service的可扩展性至关重要。

kube-proxy是为service构建路由规则的模块,之前依赖iptables来实现主要service类型的支持,比如(ClusterIP和NodePort)。但是iptables很难支持上万级的service,因为iptables纯粹是为防火墙而设计的,并且底层数据结构是内核规则的列表。

kubernetes早在1.6版本就已经有能力支持5000多节点,这样基于iptables的kube-proxy就成为集群扩容到5000节点的瓶颈。举例来说,如果在一个5000节点的集群,我们创建2000个service,并且每个service有10个pod,那么我们就会在每个节点上有至少20000条iptables规则,这会导致内核非常繁忙。

基于IPVS的集群内负载均衡就可以完美地解决这个问题。IPVS是专门为负载均衡设计的,并且底层使用哈希表这种非常高效的数据结构,几乎可以允许无限扩容。

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack
533598-20220615145036989-427831001.png

4.3 安装ipvsadm

为了便于查看ipvs的代理规则,最好安装一下管理工具ipvsadm。

yum install -y ipset ipvsadm
533598-20220615145037576-2127405396.png

5 containerd

5.1 安装containerd

containerd-{version}-linux-amd64.tar.gz 只包含containerd

cri-containerd-cni-{version}-linux-amd64.tar.gz 里面包含了systemd配置文件,containerd以及cni、runc等相关工具包,接下来我们将使用本包进行安装

打开github containerd releases,查看最新包,这里的最新版本是1.6.6

533598-20220615145038399-103264540.png

但是打开containerd.io,却发现最新版本是1.6.4

533598-20220615145038999-1925006578.png

后面我在下载1.6.6版本的时候,老是报Connection refused
533598-20220615145039506-1847039028.png

但是下载1.6.4的时候,却十分的顺利,不知道是为什么,但是并不影响我们的部署,所以接下来我们直接使用1.6.4.

wget https://github.com/containerd/containerd/releases/download/v1.6.4/cri-containerd-cni-1.6.4-linux-amd64.tar.gz
533598-20220615145040749-1357321856.png

然后我们把压缩包解压到系统的根目录中

tar zxvf cri-containerd-cni-1.6.4-linux-amd64.tar.gz -C /
533598-20220615145041379-1963907335.png

5.2 配置containerd

mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

533598-20220615145041898-1763639750.png

设置容器的cgroup驱动为systemd

533598-20220615145042412-1932907505.png

替换默认pause镜像地址

533598-20220615145042971-791157058.png

设置开机启动

systemctl enable containerd --now

533598-20220615145043522-220982490.png

测试安装结果

crictl version
533598-20220615145043996-2068745449.png

http://www.manongjc.com/detail/25-lioggelnywerjyf.html

https://www.kubernetes.org.cn/1904.html

https://www.toutiao.com/article/7105957860210819623/

https://i4t.com/5451.html

https://blog.frognew.com/2022/05/kubeadm-install-kubernetes-1.24.html

https://learn.lianglianglee.com/专栏/Kubernetes 实践入门指南/07 容器引擎 containerd 落地实践.md


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK