阅读量:0
⼀、安装环境 1. 安装说明 本次以⼆进制⽅式安装⾼可⽤ k8s 1.28.0 版本,但在⽣产环境中, 建议使⽤⼩版本⼤于 5 的 Kubernetes 版本,⽐如 1.19.5 以后。 2. 系统环境
3. ⽹络及版本环境
注:宿主机⽹段、Pod ⽹段、Service ⽹段不能重复,服务器 IP 地 址不能设置为 DHCP,需配置为静态 IP。 ⼆、前期准备 1. 配置主机映射
2. 配置 yum 源


enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/dockerce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://mirrors.aliyun.com/dockerce/linux/centos/$releasever/source/test enabled=0gpgcheck=1 gpgkey=https://mirrors.aliyun.com/dockerce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://mirrors.aliyun.com/dockerce/linux/centos/$releasever/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/dockerce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://mirrors.aliyun.com/dockerce/linux/centos/$releasever/debug- $basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/dockerce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://mirrors.aliyun.com/dockerce/linux/centos/$releasever/source/nightly

[root@k8s-master yum.repos.d]# yum makecache # 建⽴yum元数据缓存 Rocky Linux 8 - AppStream 5.2 MB/s | 9.6 MB 00:01 3. 安装必备⼯具 Rocky Linux 8 - BaseOS 2.6 MB/s | 3.9 MB 00:01 Docker CE Stable - x86_64 54 kB/s | 52 kB 00:00 Kubernetes 193 kB/s | 182 kB 00:00 元数据缓存已建⽴。
4. 关闭安全及 swap 分区
5. 同步时间
6. 配置 limit
7. 配置免密登录
8. 安装 k8s ⾼可⽤性 Git 仓库S
9. 升级系统并重启 更新系统但不包括内核
三、配置内核模块1. 配置 ipvs 模块
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units).
nf_defrag_ipv6 20480 2 nf_conntrack,ip_vs nf_defrag_ipv4 16384 1 nf_conntrack2. 配置 k8s 内核 libcrc32c 16384 5 nf_conntrack,nf_nat,nf_tables,xfs,ip_vs

nf_conntrack 172032 4 xt_conntrack,nf_nat,ipt_MASQUERADE,ip_vs nf_defrag_ipv6 20480 2 nf_conntrack,ip_vs nf_defrag_ipv4 16384 1 nf_conntrack libcrc32c 16384 5 nf_conntrack,nf_nat,nf_tables,xfs,ip_vs四、基本组件安装 1. 安装 Containerd
(2)配置 Containerd 所需模块
(3)配置 Containerd 所需内核
(4)Containerd 配置⽂件
(5)配置 crictl 客户端连接的运⾏位置
2. 安装 Kubernetes 组件 安装 Kubeadm、Kubelet 和 Kubectl
3. Kubernetes 集群初始化(1)Kubeadm 配置⽂件

(2)下载组件镜像
(3)集群初始化
(4)加载环境变量
(5)查看组件容器状态 之前采⽤初始化安装⽅式,所有的系统组件均以容器的⽅式运⾏ 并且在 kube-system 命名空间内,此时可以查看 Pod(容器 组)状态
(6)初始化失败排查 Ⅰ. 初始化重置 如果初始化失败,重置后再次初始化,命令如下(没有失败不要执 ⾏!!!)
Ⅱ. 多次初始化失败 ⾸先排查系统⽇志
Ⅲ.连接 API 服务器超时 当获取集群状态出现以下信息时:[root@master ~]# kubectl get po
The connection to the server 192.168.15.11:6443 was refused - did you specify the right host or port? 此时可以修改系统环境变量 临时修改: export KUBECONFIG=/etc/kubernetes/admin.conf ⻓期修改: mkdir ~/.kube cp /etc/kubernetes/admin.conf ~/.kube/config 如果修改环境变量后也不⾏时,需要重新进⾏初始化(依次执⾏下 ⾯两条命令) kubeadm reset -f ; ipvsadm --clear ; rm -rf ~/.kube kubeadm init --config /root/new.yaml --uploadcerts4. Master ⾼可⽤ 其他 master 加⼊集群时,输⼊如下命令 如:需要⾼可⽤时,⼜克隆了 master02、03...等,那么这些节 点都执⾏下⾯的命令 注意:每个主机的 token 值是不⼀样的,下⾯是我 192.168.15.11 (master)主机的 token 值,这是集群初始化⽣成 的代码,需要在当时记录下来
5. Token 过期处理 注意:**以下步骤是上述初始化命令产⽣的 Token 过期了才需要执 ⾏以下步骤,如果没有过期不需要执⾏,直接 join 即可。** Token 过期后⽣成新的 token
Master 需要⽣成 --certificate-key:
6. Node 节点配置 Node 节点上主要部署公司的⼀些业务应⽤,⽣产环境中不建议 Master 节点部署系统组件之外的其他 Pod,测试环境可以允许 Master 节点部署 Pod 以节省系统资源。 
(2)查看集群状态 master 上查看集群状态(NotReady 不影响)
7. Calico 组件安装 (1)切换 git 分⽀
(2)修改 Pod ⽹段
(3)查看容器和节点状态)n
ode 加⼊


















































