【K8s系列】1-Kubernetes 1.21.1集群1M2W 环境搭建

Kubernetes 1.21.1集群1M2W 环境搭建

集群说明

操作系统& 内核 ip 角色 kubeadm version docker version
Centos7 3.10.0-1160.25.1.el7.x86_64 192.168.56.186 Master 1.21.1 20.10.7
Centos7 3.10.0-1160.25.1.el7.x86_64 192.168.56.187 worker 1.21.1 20.10.7
Centos7 3.10.0-1160.25.1.el7.x86_64 192.168.56.188 worker 1.21.1 20.10.7

官方参考

官网:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

GitHub:https://github.com/kubernetes/kubeadm

配置要求

  • 一台兼容的 Linux 主机。Kubernetes 项目为基于 Debian 和 Red Hat 的 Linux 发行版以及一些不提供包管理器的发行版提供通用的指令
  • 每台机器 2 GB 或更多的 RAM (如果少于这个数字将会影响你应用的运行内存)
  • 2 CPU 核或更多
  • 集群中的所有机器的网络彼此均能相互连接(公网和内网都可以)
  • 节点之中不可以有重复的主机名、MAC 地址或 product_uuid。请参见这里了解更多详细信息。
  • 开启机器上的某些端口。请参见这里 了解更多详细信息。
  • 禁用交换分区。为了保证 kubelet 正常工作,你 必须 禁用交换分区。

每个节点的检查环节

MAC 地址唯一性

  • 你可以使用命令 ip linkifconfig -a 来获取网络接口的 MAC 地址
# mac 地址校验
ifconfig -a

product_uuid 的唯一性

  • 可以使用 sudo cat /sys/class/dmi/id/product_uuid 命令对 product_uuid 校验

一般来讲,硬件设备会拥有唯一的地址,但是有些虚拟机的地址可能会重复。 Kubernetes 使用这些值来唯一确定集群中的节点。

#  product_uuid 校验
sudo cat /sys/class/dmi/id/product_uuid

允许 iptables 检查桥接流量

确保 br_netfilter 模块被加载。这一操作可以通过运行 lsmod | grep br_netfilter 来完成。若要显式加载该模块,可执行 sudo modprobe br_netfilter

[root@w2 ~]# lsmod | grep br_netfilter
br_netfilter           22256  0 
bridge                151336  1 br_netfilter

为了让你的 Linux 节点上的 iptables 能够正确地查看桥接流量,你需要确保在你的 sysctl 配置中将 net.bridge.bridge-nf-call-iptables 设置为 1

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

系统版本统一

内核版本

Docker 要求 CentOS 系统的内核版本高于 3.10

$ uname -r
3.10.0-1160.25.1.el7.x86_64

系统基础前提配置

# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld

# 关闭selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

# 关闭swap
swapoff -a
sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab

# 配置iptables的ACCEPT规则
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT

# 时钟同步
yum install ntpdate -y && ntpdate time.windows.com

网络配置

访问外网

每个节点需要开启NAT网络模式,可访问宿主机的外网环境

配置网卡网段

大家根据自己的情况来准备centos7的虚拟机。

要保证彼此之间能够ping通,也就是处于同一个网络中

也可以按如下操作:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xianghan收藏册

极简精品作,一分也是一份鼓励哦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值