1、环境准备
(1)配置好网络ip和主机名
control:
node1:
node2:
配置ip 主机名的过程省略
配置一个简单的基于hosts文件的名称解析
[root@node1 ~]# vim /etc/hosts
// 文件中新增以下三行
192.168.110.10 control
192.168.110.11 node1
192.168.110.22 node2
[root@node1 ~]# scp /etc/hosts root@node1:/etc/hosts
The authenticity of host 'node1 (192.168.110.11)' can't be established.
ED25519 key fingerprint is SHA256:84EopGSflyn0EP7RLvmnvaWPJCTe8G99eX4dF6XQzFk.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'node1' (ED25519) to the list of known hosts.
root@node1's password:
hosts 100% 223 251.9KB/s 00:00
[root@node1 ~]# scp /etc/hosts root@control:/etc/hosts
The authenticity of host 'control (192.168.110.10)' can't be established.
ED25519 key fingerprint is SHA256:84EopGSflyn0EP7RLvmnvaWPJCTe8G99eX4dF6XQzFk.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: node1
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'control' (ED25519) to the list of known hosts.
root@control's password:
hosts 100% 223 103.3KB/s 00:00
[root@node1 ~]# scp /etc/hosts root@node2:/etc/hosts
The authenticity of host 'node2 (192.168.110.22)' can't be established.
ED25519 key fingerprint is SHA256:84EopGSflyn0EP7RLvmnvaWPJCTe8G99eX4dF6XQzFk.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: node1
~/.ssh/known_hosts:4: control
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'node2' (ED25519) to the list of known hosts.
root@node2's password:
hosts
(2)允许root用户远程登录
从第三步开始,所有的操作需要在三个节点上一起执行。
(3)调整防火墙
[root@control ~]# systemctl disable --now firewalld.service
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@control ~]# nft flush ruleset
(4)允许系统转发ipv4数据包
[root@control ~]# vim /etc/sysctl.d/k8s.conf
[root@control ~]# cat /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
[root@control ~]# sysctl -f /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
[root@control ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
(5)设置容器运行时
[root@control ~]# dnf remove -y podman container* runc*
[root@control ~]# dnf -y install dnf-utils //安装仓库配置命令行工具
[root@control ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
设置docker 仓库,安装docker和containerd 服务。
docker 对于容器进行管理的客户端架构,docker只是将用户指令打包给containerd 进行容器启动 停止等控制容器的操作。
containerd 实际的容器管理服务
[root@control ~]# dnf makecache
Waiting for process with pid 33407 to finish.
CentOS Stream 9 - BaseOS 1.3 kB/s | 7.5 kB 00:05
CentOS Stream 9 - AppStream 1.3 kB/s | 7.7 kB 00:05
CentOS Stream 9 - Extras packages 1.6 kB/s | 8.6 kB 00:05
Docker CE Stable - x86_64 1.8 kB/s | 58 kB 00:32
Metadata cache created.
[root@control ~]# dnf install docker-ce docker-ce-cli containerd.io
[root@control ~]# systemctl enable --now containerd.service
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /usr/lib/systemd/system/containerd.service.
[root@control ~]# containerd config dump > /etc/containerd/config.toml // 生成完整配置文件
[root@control ~]# containerd config default > /etc/containerd/config.toml // 生成完整配置文件
[root@control ~]# vim /etc/containerd/config.toml
[root@control ~]# systemctl restart containerd.service
(6)禁用swap交换分区
[root@control ~]# swapoff -a
[root@control ~]# vim /etc/fstab
[root@control ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Aug 23 00:45:24 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cs_bogon-root / xfs defaults 0 0
UUID=d910d323-150c-40df-bd32-bdfb1f5c93b9 /boot xfs defaults 0 0
UUID=BA00-CA1F /boot/efi vfat umask=0077,shortname=winnt 0 2
#/dev/mapper/cs_bogon-swap none swap defaults 0 0 // 禁止交换分区在重启后挂载激活
二、K8s安装和集群初始化
(1)安装K8S 安装工具的软件包
[root@control ~]# setenforce 0
[root@control ~]#
[root@control ~]# grep ^SELINUX= /etc/selinux/config