组件
版本
发布时间
kubernetes
v1.23.3
2022-01-26
etcd
v3.5.2
2022-02-01
cri-o
v1.23.0
2021-12-18
flannel
v0.16.3
2022-01-29
coredns
1.9.0
2022-02-10
cni-plugins
v1.0.1
2021-09-08
kube-apiserver:
kube-controller-manager:
kube-scheduler:
kubelet:
kube-proxy:
集群插件:
master节点:
节点名称
IP地址
k8s-master-1
192.168.2.175
k8s-master-2
192.168.2.176
k8s-master-3
192.168.2.178
node 节点:
节点名称
IP地址
k8s-node-1
192.168.2.185
k8s-node-2
192.168.2.187
k8s-node-3
192.168.3.62
k8s-node-4
192.168.3.70
控制节点/配置生成节点:
节点名称
IP地址
qist
192.168.0.151
工作目录: /opt
三台机器混合部署本文档的 etcd、master 集群和 woker 集群。
如果没有特殊说明,需要在所有节点上执行本文档的初始化操作。
Cgroup Driver:systemd
kubeelt cri-o Cgroup 配置为systemd
hostnamectl set-hostname k8s-master-1 # 将 k8s-master-1 替换为当前主机名
退出,重新登录 root 账号,可以看到主机名生效。
本操作只需要在 qist 节点上进行,设置 root 账户可以无密码登录所有节点:
ssh-keygen -t rsa
ssh-copy-id root@192.168.2.175
ssh-copy-id root@192.168.2.176
ssh-copy-id root@192.168.2.177
ssh-copy-id root@192.168.2.185
ssh-copy-id root@192.168.2.187
ssh-copy-id root@192.168.3.62
ssh-copy-id root@192.168.3.70
yum install -y epel-release
yum install -y chrony conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget socat git
关闭防火墙,清理防火墙规则,设置默认转发策略:
systemctl stop firewalld
systemctl disable firewalld
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat
关闭 swap 分区,否则kubelet 会启动失败(可以设置 kubelet 启动参数 --fail-swap-on 为 false 关闭 swap检查):
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
关闭 SELinux,否则 kubelet 挂载目录时可能报错 Permission denied :
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
cat > /etc/sysctl.d/kubernetes.conf <<EOF
net.ipv4.tcp_slow_start_after_idle=0
net.core.rmem_max=16777216
fs.inotify.max_user_watches=1048576
kernel.softlockup_all_cpu_backtrace=1
kernel.softlockup_panic=1
fs.file-max=2097152
fs.nr_open=2097152
fs.inotify.max_user_instances=8192
fs.inotify.max_queued_events=16384
vm.max_map_count=262144
net.core.netdev_max_backlog=16384
net.ipv4.tcp_wmem=4096 12582912 16777216
net.core.wmem_max=16777216
net.core.somaxconn=32768
net.ipv4.ip_forward=1
net.ipv4.tcp_max_syn_backlog=8096
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-arptables=1
net.ipv4.tcp_rmem=4096 12582912 16777216
vm.swappiness=0
kernel.sysrq=1
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_synack_retries=2
net.ipv6.conf.lo.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.all.forwarding=0
net.ipv4.ip_local_port_range=1024 65535
net.ipv4.tcp_keepalive_time=600
net.ipv4.tcp_keepalive_probes=10
net.ipv4.tcp_keepalive_intvl=30
net.nf_conntrack_max=25000000
net.netfilter.nf_conntrack_max=25000000
net.netfilter.nf_conntrack_tcp_timeout_established=180
net.netfilter.nf_conntrack_tcp_timeout_time_wait=120
net.netfilter.nf_conntrack_tcp_timeout_close_wait=60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait=12
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_orphan_retries=3
fs.may_detach_mounts=1
kernel.pid_max=4194303
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_fin_timeout=1
vm.min_free_kbytes=262144
kernel.msgmnb=65535
kernel.msgmax=65535
kernel.shmmax=68719476736
kernel.shmall=4294967296
kernel.core_uses_pid=1
net.ipv4.neigh.default.gc_thresh1=0
net.ipv4.neigh.default.gc_thresh2=4096
net.ipv4.neigh.default.gc_thresh3=8192
net.netfilter.nf_conntrack_tcp_timeout_close=3
net.ipv4.conf.all.route_localnet=1 EOF
sysctl -p /etc/sysctl.d/kubernetes.conf
cat>>/etc/security/limits.conf<<EOF
* soft nofile 655350
* hard nofile 655350
* soft nproc 655350
* hard nproc 655350
* soft core unlimited
* hard core unlimited
EOF
centos7还需修改
sed-i's/4096/655350/'/etc/security/limits.d/20-nproc.conf
加载ipvs内核模块
cat>/etc/modules-load.d/k8s-ipvs-modules.conf<<EOF ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
EOF
加载netfilter等模块
内核4版本以下 nf_conntrack 替换 nf_conntrack_ipv4
cat>/etc/modules-load.d/k8s-net-modules.conf<<EOF br_netfilter
nf_conntrack
EOF
timedatectlset-timezoneAsia/Shanghai
systemctl enable chronyd
systemctl start chronyd
查看同步状态:
timedatectl status
输出:
System clock synchronized: yes
NTP service: active
RTC in localTZ: no
System clock synchronized: yes,表示时钟已同步;
NTP service: active,表示开启了时钟同步服务;
#将当前的UTC时间写入硬件时钟
timedatectlset-local-rtc0
#重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
systemctl stop postfix && systemctl disable postfix
创建目录:
master 组件目录
#k8s目录
mkdir -p /apps/k8s/{bin,log,conf,ssl,config}
mkdir -p /apps/work/kubernetes/{manifests,kubelet}
mkdir -p /var/lib/kubelet
mkdir- p /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
mkdir -p /apps/k8s/ssl/{etcd,k8s}
#etcd目录
mkdir -p /apps/etcd/{bin,conf,data,ssl}
#etcd data-dir目录
mkdir -p /apps/etcd/data/default.etcd
#etcdwal-dir目录
mkdir -p /apps/etcd/data/default.etcd/wal
node 节点目录
mkdir -p /apps/k8s/{bin,log,conf,ssl}
mkdir -p /apps/work/kubernetes/{manifests,kubelet}
mkdir -p /var/lib/kubelet
mkdir -p /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
cri-o 目录结构创建
mkdir -p /apps/crio/{run,etc,keys}
mkdir -p /apps/crio/containers/oci/hooks.d
mkdir -p /etc/containers
mkdir -p /var/lib/containers/storage
mkdir -p /run/containers/storage
mkdir -p /apps/crio/lib/containers/storage
mkdir -p /apps/crio/run/containers/storage
挂载kubelet 跟cri-o数据目录最大兼容其它依赖组件例如csi插件
cat>> /etc/fstab <<EOF
/apps/work/kubernetes/kubelet /var/lib/kubelet none defaults,bind,nofail 0 0
/apps/crio/lib/containers/storage /var/lib/containers/storage none defaults,bind,nofail 0 0
/apps/crio/run/containers/storage /run/containers/storage none defaults,bind,nofail 0 0
EOF
验证挂载是否有误
mount-a
重启机器:
sync
reboot
期待下次的分享,别忘了三连支持博主呀~
我是 念舒_C.ying ,期待你的关注~
手机扫一扫
移动阅读更方便
你可能感兴趣的文章