系统: centos7
XFS文件系统要带 ftype=1 进行格式化
kubernetes 1.24.2
# 更改為overlay2
一、创建XFS文件系统
# fdisk /dev/sdb
n
p
1
w
# pvcreate /dev/sdb1
# vgextend centos /dev/sdb1
# lvcreate -L 5G -n lv_docker centos
# mkfs -t xfs -n ftype=1 /dev/mapper/centos-lv_docker
编辑 /etc/hosts 文件添加名称解析、关闭防火墙、selinux和swap
# systemctl stop firewalld
# systemctl disable firewalld
# setenforce 0
# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# swapoff -a
# sed -i 's/.*swap.*/#&/' /etc/fstab
二、开启内核模块
# cat > /etc/modules-load.d/k8s.conf <<LOYU
overlay
br_netfilter
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
ip_conntrack
LOYU
配置内核参数,将桥接的IPv4流量传递到iptables的链
# cat > /etc/sysctl.d/k8s.conf <<EOF
#开启网桥模式【重要】
net.bridge.bridge-nf-call-iptables=1
#开启网桥模式【重要】
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
#禁止使用swap空间,只有当系统OOM时才允许使用它
vm.swappiness=0
#不检查物理内存是否够用
vm.overcommit_memory=1
#开启OOM
vm.panic_on_oom=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
#关闭ipv6【重要】
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
# sysctl --system
三、配置Kubernetes源
(任选一)
国内源
# cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
国外源
# cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
四、配置Docker源(containerd安装也是用这个源)
# yum -y install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
国内源(https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo)
五、安装依赖
# yum -y install epel-release container-selinux ipset ipvsadm libtool-ltdl libseccomp yum-plugin-ovl yum-utils device-mapper-persistent-data lvm2
# yum makecache fast
指定要安装的kubernetes 版本
# 在 master 节点和 worker 节点都要执行
# 指定k8s版本
export K8S_VERSION=1.24.2
# 指定Containerd版本
export CONTAINERD_VERSION=1.6.6