Centos7.9使用kubeadm部署K8S 1.27.6集群环境(内网通过代理部署)

Centos7.9使用kubeadm部署K8S 1.27.6集群环境(内网通过代理部署)

在内网借助代理服务器,使用kubeadm部署一个k8s集群,单master+2worker节点,K8S版本为1.27.6,使用containerd作为容器运行时。

1. 环境信息

  • 操作系统:CentOS 7.9.2009
  • 内存: 8GB
  • CPU: 4
  • 网络: 节点通过代理进行访问。
hostname ip 备注
k8s-master1 10.210.10.201 master
k8s-node1 10.210.10.202 worker
k8s-node2 10.210.10.203 worker

2. 准备工作

2.1 配置网络代理

# 配置全局代理
export proxy=http://10.0.112.18:808
export all_proxy=$proxy
export no_proxy=localhost,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12

# 持久化配置可以将上面配置写/etc/profile文件

在k8s初始化的时候,容器拉取镜像需要单独配置代理:

# docker代理
[root@k8s-master1 ~]# mkdir -p /etc/systemd/system/docker.service.d
[root@k8s-master1 ~]# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.0.112.18:808"
Environment="HTTPS_PROXY=http://10.0.112.18:808"
Environment="NO_RPOXY=localhost,127.0.0.1"

# containerd代理
[root@k8s-master1 ~]# mkdir -p /etc/systemd/system/containerd.service.d
[root@k8s-master1 ~]# cat /etc/systemd/system/containerd.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.0.112.18:808"
Environment="HTTPS_PROXY=http://10.0.112.18:808"
Environment="NO_RPOXY=localhost,127.0.0.1"

说明:

K8S 1.24版本后启用了docker-shim容器运行时,本地安装的k8s版本为1.27.6,选用containd作为容器运行,可以只配置containerd的代理。由于每个节点都要运行容器,所以代理需要在每个节点都需要配置。

2.2 linux基础配置

以下操作在所有节点执行:

# 配置yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

# 安装常用软件
yum install wget vim-enhanced net-tools

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

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

# 关闭 selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

设置hosts:

# 设置主机名
hostnamectl set-hostname k8s-master1  # k8s-node1 / k8s-node2
hostname

# 配置 hosts
cat >> /etc/hosts << EOF
10.210.10.201 k8s-master1
10.210.10.202 k8s-node1
10.210.10.203 k8s-node2
EOF

由于环境在内网,没有ntp服务器。这里手动修改时间,也可以配置内部的ntp服务器。

# 设置时区
timedatectl set-timezone Asia/Shanghai

# 将系统时间改为utc时间(如果需要)。编辑下面文件,写入ZONE="Etc/UTC"
vi /etc/sysconfig/clock

# 建立软连接
ln -sf /usr/share/zoneinfo/UTC /etc/localtime

# 设置系统时间为当前时间
date -s "2024-06-20 19:04:00"

# 同步硬件时间
hwclock --systohc

配置内核参数:

cat >/etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter


# 将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
EOF

sysctl --system  # 生效

# 通过运行以下指令确认 br_netfilter 和 overlay 模块被加载
lsmod | egrep 'overlay|br_netfilter'
# 确认sysctl配置中被设置为 1
sysctl net.bridge.bridge-nf-call-iptables net.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

lldhsds

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值