1. 准备环境
版本:
kubernetes: v1.29.2
kubesphere: v3.4.1
kubekey: v3.1.1
说明:
- kubekey 只用于安装 kubernetes,因为 kubesphere 的配置在安装时经常需要变动,用 ks-installer 的 yaml 文件更好管理;
- ks-installer 用于安装 kubesphere,kubekey、ks-installer 分工明确;
- 本文在已有 harbor 仓库环境下,建议把镜像都放在公开仓库
library
中,如没有 harbor 仓库,按官方文档来即可;
1.1 机器准备
4 台机器,操作系统:Ubuntu 24.04/RHEL8/CentOS9
1.2 离线安装包准备
这里提供一个可以直接使用的,因为系统安装包,我们自己处理,所以这里不用管系统的 iso 啥的地址。
manifest-sample.yaml
:
因为最近 docker hub 无法在大陆拉 image,可以使用我这个 Jenkinsfile 配合海外节点将 image 拉下来,传到私有 harbor 仓库。
mirror-images-to-harbor,当前直接在它上面提 issue 同步也可,只是一个 issue 只能同步一个 image。
当然,官方的这个 image 同步脚本 offline-installation-tool.sh 也可以,它是直接拉的 image,可能拉不动,你下面列表里的 image 得转成你拉得动的 image 地址:
以下为image列表,生成的 image 列表,并不完全,所以后面发现有漏的 image,随时使用 jenkins 把缺少的image同步下。
1.3 安装依赖和配置
系统源即可安装的依赖包,所有节点都需要执行
Ubuntu 系:
RHEL 系:
因为使用私有 Harbor 仓库,所有节点配置 host:
10.25.23.102 harbor.ops.shenzhen.com
1.4 安装负载均衡 keepalived + haproxy
负载均衡节点安装 keepalived haproxy
新建用户
配置 keepalived
/etc/keepalived/keepalived.conf
(注意配置中注释,不同节点权重不同)内容:
/etc/keepalived/check_apiserver.sh
内容:
chmod a+x /etc/keepalived/check_apiserver.sh
配置 haproxy
/etc/haproxy/haproxy.cfg
内容:
2. kubernetes 集群安装
2.1 kk 安装
kk 命令是二进制的,从安装好的机器,直接拷贝到安装集群的 master 机器即可。
2.2 kk 配置
直接使用如下配置文件 config-sample.yaml
,然后修改下节点信息,如下:
内容:
2.3 kk 安装集群
检查时间,如果时间未同步,重启 chronyd 服务。
集群安装:
如果使用的 harbor 是 http 的,kubekey 内部是使用的 https 的仓库,可能会中断安装。我们再次安装,前面二进制文件已经缓存至 kubekey 安装目录,然后不加 -a
参数,就是在线安装,只是使用内部仓库的在线安装方式。
再次集群安装:
有可能需要处理的地方
/etc/containerd/config.toml
,里面改成私有仓库地址
- 如果你需要 coredns 添加 hosts,注意
/etc/resolv.conf
里面要设置 DNS,否则 coredns 可能无法启动。
kubectl edit cm coredns -n kube-system
:
kubectl edit cm nodelocaldns -n kube-system
:
2.4 kk 安装集群失败处理
在 master 节点执行,注意确认正确的节点和危险性!!!
3. kubesphere 安装
根据官方文档来即可。
安装:
最容易出问题的就是镜像拉取,随时查看并解决镜像问题。
4. 暴露 kubesphere 控制台
4.1 安装 metallb
推荐 helm 方式安装,这里略,详情参考 metallb官方文档。
安装好后配置一个全局 IP 池。
4.2 打开全局网关
使用 http://某一节点IP:30880
登录 ks 后,在集群设置中,打开全局网关,注意使用 Loadbalancer
类型暴露,因为有全局 IP 池可用,按理说随便选一个负载均衡厂商即可,因为没有 metallb 选项。
4.3 ingress 暴露 ks 控制台
console-ingress.yaml
参考资料:
[1] https://www.kubesphere.io/zh/docs/v3.4/installing-on-linux/introduction/air-gapped-installation/
[2] https://www.kubesphere.io/zh/docs/v3.4/installing-on-kubernetes/on-prem-kubernetes/install-ks-on-linux-airgapped/