Kubernetes有两种方式,第一种是二进制的方式,可定制但是部署复杂容易出错;第二种是kubeadm工具安装,部署简单,不可定制化。本次我们部署二进制安装.
服务器配置至少是2G2核的。如果不是则可以在集群初始化后面增加 --ignore-preflight-errors=NumCPU
k8s和docker之间的关系?
k8s是一个容器化管理平台,docker是一个容器,
| 软件 | 版本 | | --------------- | ----------------------------------------------- | | Centos | 7.5版本及以上 | | Docker | 19.03及以上 | | Kubernetse | V1.19.1及以上 | | Flanner | V0.13.0及以上 | | Kernel-lm | kernel-lt-4.4.245-1.el7.elrepo.x86_64.rpm及以上 | | Kernel-lm-devel | kernel-lt-devel-4.4.245-1.el7.elrepo.x86_64.rpm |
| Hostname | Ip | | -------- | ------------- | | k8s-m-01 | 192.168.15.51 | | k8s-m-02 | 192.168.15.52 | | k8s-m-03 | 192.168.15.53 | | k8s-n-01 | 192.168.15.54 | | k8s-n-02 | 192.168.15.55 |
略
内网eth1也要不同IP否则三台机器IP冲突。修改完成后重启网卡,ping baidu.com 查看网络是否畅通
hostnamectl set-hostname k8s-m-01
hostnamectl set-hostname k8s-m-02
hostnamectl set-hostname k8s-m-03
hostnamectl set-hostname k8s-n-01
hostnamectl set-hostname k8s-n-02
vim /etc/hosts
192.168.15.51 k8s-m-01 m1
192.168.15.52 k8s-m-02 m2
192.168.15.53 k8s-m-03 m3
192.168.15.54 k8s-n-01 n1
192.168.15.55 k8s-n-02 n2
vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 114.114.114.114
# 永久关闭
sed -i 's#enforcing#disabled#g' /etc/selinux/config
#临时关闭
setenforce 0
systemctl disable --now firewalld
# 关闭swap分区
swapoff -a
# kubelet忽略swap
echo 'KUBELET_EXTRA_ARGS="--fail-swap-on=false"' > /etc/sysconfig/kubelet
# 注释swap分区
vim /etc/fstab
[root@k8s-m-01 ~]# rm -rf /root/.ssh
[root@k8s-m-01 ~]# ssh-keygen 交互式直接全部回车
[root@k8s-m-01 ~]# cd /root/.ssh/
[root@k8s-m-01 ~/.ssh]# mv id_rsa.pub authorized_keys
[root@k8s-m-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.51:/root
[root@k8s-m-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.52:/root
[root@k8s-m-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.53:/root
[root@k8s-m-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.54:/root
[root@k8s-m-01 ~/.ssh]# scp -r /root/.ssh 192.168.15.55:/root
echo '#Timing synchronization time' >>/var/spool/cron/root #给定时任务加上注释
echo '0 */1 * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null' >>/var/spool/cron/root #设置定时任务
crontab -l #检查结果
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum install -y https://repo.huaweicloud.com/epel/epel-release-latest-7.noarch.rpm
sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
sed -i "s/metalink/#metalink/g" /etc/yum.repos.d/epel.repo
sed -i "s@https\?://download.fedoraproject.org/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo
yum clean all
yum makecache
yum update -y --exclud=kernel*
yum install wget expect vim net-tools ntp bash-completion ipvsadm ipset jq iptables conntrack sysstat libseccomp -y
主节点操作
[root@k8s-m-01 ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.107-1.el7.elrepo.x86_64.rpm
[root@k8s-m-01 ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-devel-5.4.107-1.el7.elrepo.x86_64.rpm
[root@k8s-m-01 ~]# for i in m1 m2 m3 n1 n2 ; do scp kernel-lt-* $i:/opt; done
五个节点操作
#安装
yum localinstall -y /opt/kernel-lt*
#调到默认启动
grub2-set-default 0 && grub2-mkconfig -o /etc/grub2.cfg
#查看当前默认启动的内核
grubby --default-kernel
#重启系统
reboot
yum install -y conntrack-tools ipvsadm ipset conntrack libseccomp
cat > /etc/sysconfig/modules/ipvs.modules <