k8s安装节点教程(亲测成功)

配置hosts

每一台都设置

vim /etc/hosts

追加如下内容

192.168.18.10 k8s-master
192.168.18.11 k8s-node1
192.168.18.12 k8s-node2
192.168.18.13 k8s-admin

安装依赖包

yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vimnet-tools git

配置防火墙

设置防火墙为 Iptables 并设置空规则

systemctl stop firewalld && systemctl disable firewalld
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save

关闭selinux

sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0

关闭swap分区

两条命令都需要执行

# 临时关闭
swapoff -a

# 永久关闭,下次生效
sed -ri 's/.*swap.*/#&/' /etc/fstab

调整内核参数

cat > kubernetes.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
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF


cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
sysctl -p /etc/sysctl.d/kubernetes.conf

调整系统时区

rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai
reboot

关闭系统不需要服务

systemctl stop postfix && systemctl disable postfix

设置 rsyslogd 和 systemd journald

mkdir /var/log/journal # 持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf << EOF
[Journal]
Storage=persistent
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
SystemMaxUse=10G
SystemMaxFileSize=200M
MaxRetentionSec=2week
ForwardToSyslog=no
EOF
systemctl restart systemd-journald

升级系统内核

CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes 不稳定。

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含initrd16配置,如果没有,再安装一次!

cat /boot/grub2/grub.cfg | grep initrd16
yum --enablerepo=elrepo-kernel install -y kernel-lt

设置开机从新内核启动

grub2-set-default 'CentOS Linux (4.4.189-1.el7.elrepo.x86_64) 7 (Core)'

检查一下

reboot
uname -r 

设置主机名

# k8s-node1
hostnamectl set-hostname k8s-node1

# k8s-node2
hostnamectl set-hostname k8s-node2

# k8s-admin
hostnamectl set-hostname k8s-admin

加载ip_vs内核模块

modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4

设置下次开机自动加载

cat > /etc/modules-load.d/ip_vs.conf << EOF 
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4
EOF

安装kubeadm,kubelet和kubectl

配置yum源(这里使用阿里云的源)

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

安装指定版本的kubeadm,kubelet,kubectl

扫描二维码关注公众号,回复: 13651653 查看本文章
yum install -y kubelet-1.18.8 kubeadm-1.18.8 kubectl-1.18.8

设置开机自启

systemctl enable kubelet

node节点加入集群

kubeadm join 192.168.18.10:6443 --token hh87xr.3kwc9qg7javs8066 \
    --discovery-token-ca-cert-hash sha256:b8a0250c1e97f00c993efd566d40305df818b0966fea73ece417228769e56b1c 

猜你喜欢

转载自blog.csdn.net/qq_37703224/article/details/122335428