《Kubernetes部署篇:Ubuntu20.04基于外部etcd+部署kubernetes1.24.12集群(一主多从)》

该博客详细介绍了如何在Ubuntu 20.04上,基于外部etcd集群部署Kubernetes 1.24.12的一主多从架构。内容涵盖主机名设置、防火墙关闭、内核参数调整、etcd集群安装、containerd和Kubernetes组件安装、镜像下载、集群初始化、节点加入及测试。
摘要由CSDN通过智能技术生成

一、架构图

如下图所示:
在这里插入图片描述


二、环境信息

主机名 K8S版本 系统版本 内核版本 IP地址 备注
etcd01 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.62 etcd节点
etcd02 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.63 etcd节点
etcd03 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.64 etcd节点
k8s-master-65 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.64 master节点
k8s-worker-66 1.24.12 Ubuntu 20.04.5 LTS 5.15.0-69-generic 192.168.1.64 worker节点

三、安装和配置先决条件

3.1、主机名设置

说明:分别在对应的节点IP上设置主机名。

root@lolaage-virtual-machine:~#  hostnamectl set-hostname etcd01
root@lolaage-virtual-machine:~#  hostnamectl set-hostname etcd02
root@lolaage-virtual-machine:~#  hostnamectl set-hostname etcd03
root@lolaage-virtual-machine:~#  hostnamectl set-hostname k8s-master-65
root@lolaage-virtual-machine:~#  hostnamectl set-hostname k8s-worker-66

3.2、配置主机hosts

说明:以下操作无论是master节点和worker节点均需要执行。

vim /etc/hosts
192.168.1.62 etcd01
192.168.1.63 etcd02
192.168.1.64 etcd03
192.168.1.65 k8s-master-65
192.168.1.66 k8s-worker-66

3.3、关闭防火墙

说明:以下操作无论是master节点和worker节点均需要执行。

ufw status
ufw disable

3.4、关闭selinux

说明:以下操作无论是master节点和worker节点均需要执行。

apt install selinux-utils
apt install policycoreutils
sed -i 's#SELINUX=permissive#SELINUX=disabled#g' /etc/selinux/config
sestatus -v

说明:如果selinux默认关闭则无需修改。


3.5、关闭swap分区

说明:以下操作无论是master节点和worker节点均需要执行。

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

3.6、时间时区同步

说明:以下操作无论是master节点和worker节点均需要执行。

1、设置时区为Asia/Shanghai,如果已经是则请忽略

root@k8s-master-65:~# timedatectl
               Local time: 五 2023-03-31 14:11:36 CST
           Universal time: 五 2023-03-31 06:11:36 UTC
                 RTC time: 五 2023-03-31 06:11:36    
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes                       
              NTP service: active                    
          RTC in local TZ: no  

2、使用chrony同步时间

root@k8s-master-65:~# apt install chrony -y
root@k8s-master-65:~# vim /etc/chrony/chrony.conf
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
#pool ntp.ubuntu.com        iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2

root@k8s-master-65:~# systemctl enable chronyd.service
root@k8s-master-65:~# systemctl restart chronyd.service
root@k8s-master-65:~# systemctl status chronyd.service

阿里云NTP服务器地址列表,状态检测如下所示:
在这里插入图片描述

然后就是chrony客户端上的一些常用命令:

#查看可用的时间同步源
chronyc sources -v
 
#查看时间同步源的状态
chronyc sourcestats -v
 
#对客户端系统时间进行强制同步
chronyc -a makestep

3.7、修改内核参数

说明:以下操作无论是master节点和worker节点均需要执行。

说明:有一些ipv4的流量不能走iptables链,因为linux内核的一个过滤器,每个流量都会经过他,然后再匹配是否可进入当前应用进程去处理,所以会导致流量丢失。配置k8s.conf文件,如下所示:

root@k8s-master-65:~# cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

root@k8s-master-65:~# modprobe overlay
root@k8s-master-65:~# modprobe br_netfilter

# 设置所需的sysctl参数,参数在重新启动后保持不变
root@k8s-master-65:~# cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# 应用sysctl参数而不重新启动
root@k8s-master-65:~# sysctl --system

3.8、启用IPVS模式

说明:以下操作无论是master节点和worker节点均需要执行。

说明:ube-proxy开启ipvs的前提需要加载以下的内核模块

ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4

注意:如果出现modprobe: FATAL: Module nf_conntrack_ipv4 not found in directory /lib/modules/5.15.0-69-generic错误,这是因为使用了高内核,当前内核版本为5.15.0-69-generic,在高版本内核已经把nf_conntrack_ipv4替换为nf_conntrack了。

# 1、安装ipvs
root@k8s-master-65:~#  apt -y install ipvsadm ipset sysstat conntrack

# 2、加载内核模块脚本
root@k8s-master-65:~# cat > /etc/profile.d/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/profile.d/ipvs.modules

#3、执行加载模块脚本
bash /etc/profile.d/ipvs.modules &&<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Ubuntu 20.04部署 Kubernetes 1.24 集群的步骤如下: 1. 确保每台机器上都安装了 Docker 和 Kubernetes 关软件包。可以使用以下命令安装: ``` sudo apt-get update sudo apt-get install docker.io sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl ``` 2. 在其中一台机器上初始化 Kubernetes 集群。运行以下命令: ``` sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ``` 其中,`--pod-network-cidr=10.244.0.0/16` 是一个必需的参数,用于指定 Pod 网络的 CIDR。这里我们使用 Flannel 网络插件,默认使用的 Pod 网络 CIDR 是 `10.244.0.0/16`。 3. 安装 Pod 网络插件。运行以下命令: ``` sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml ``` 4. 将 Kubernetes 集群加入到其他机器上。运行以下命令: ``` sudo kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert-hash <hash> ``` 其中,`<master-ip>` 是 Kubernetes 主节点的 IP 地址,`<master-port>` 是 Kubernetes 主节点的端口号,`<token>` 和 `<hash>` 是在初始化 Kubernetes 集群时生成的。 5. 等待所有节点加入成功。运行以下命令检查节点状态: ``` sudo kubectl get nodes ``` 如果所有节点都已加入成功,将显示所有节点的状态信息。 以上就是在 Ubuntu 20.04部署 Kubernetes 1.24 集群的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

东城绝神

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

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

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

打赏作者

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

抵扣说明:

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

余额充值