kubeadm快速安装最新版 Kubernetes(k8s)1.27.2

1 准备环境

单master部署

IP Role
192.168.1.20 master
192.168.1.21 node01
192.168.1.22 node02

1.1 k8s环境配置(所有节点都需要操作)

1.2.主机名

hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node01
hostnamectl set-hostname k8s-node02

1.3 配置yum源

1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
centos8(centos8官方源已下线,建议切换centos-vault源)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
centos6(centos6官方源已下线,建议切换centos-vault源)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3. 运行 yum makecache 生成缓存
4. 其他
非阿里云ECS用户会出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影响使用。用户也可自行修改相关配置: eg:
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

1.4 安装一些必备工具

yum update -y && yum -y install  wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl

1.5 关闭防火墙

# Ubuntu忽略,CentOS执行
systemctl disable --now firewalld

1.6 关闭SELinux

禁用SELinux的目的是让容器可以读取主机文件系统
sudo setenforce 0

sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

1.7 关闭swap

禁用交换分区。为了保证 kubelet 正常工作,你必须禁用交换分区。

swapoff -a

sed -ri 's/.*swap.*/#&/' /etc/fstab

1.8 网络配置(俩种方式二选一)

#Ubuntu忽略,CentOS执行

 方式一
 systemctl disable --now NetworkManager
 systemctl start network && systemctl enable network

 方式二
cat > /etc/NetworkManager/conf.d/calico.conf << EOF 
[keyfile]
unmanaged-devices=interface-name:cali*;interface-name:tunl*
EOF
systemctl restart NetworkManager

1.9 .进行时间同步

master 节点设置

yum -y install chrony
vim /etc/chrony.conf
server ntp.aliyun.com iburst

systemctl start chronyd && systemctl enable chronyd && timedatectl set-timezone Asia/Shanghai
chronyc sources

node 节点设置
 yum -y install chrony  
  vim /etc/chrony.conf
  
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.1.20
systemctl start chronyd && systemctl enable chronyd 
chronyc sources
# 快捷f方式

# 服务端
# apt install chrony -y
yum install chrony -y
cat > /etc/chrony.conf << EOF 
pool ntp.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.0.0/24
local stratum 10
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony
EOF

systemctl restart chronyd ; systemctl enable chronyd

# 客户端
# apt install chrony -y
yum install chrony -y
cat > /etc/chrony.conf << EOF 
pool 192.168.1.20 iburst
driftfile /var/lib/chrony/dr

你可能感兴趣的:(部署专题,kubernetes,运维,docker,centos,linux)