离线安装高可用k3s集群

一、安装前准备

基础环境准备

二、K3S离线包下载

1、查看需要下载的安装包版本匹配情况

https://rancher.com/support-maintenance-terms/all-supported-versions/rancher-v2.5.5/

2、下载离线安装包

k3s URL:
https://github.com/k3s-io/k3s/releases
找到v1.19.5-k3s+2版本的URL:
https://github.com/k3s-io/k3s/releases/tag/v1.19.5%2Bk3s2

k3s 国内 URL:
http://mirror.cnrancher.com
国内会少一些东西。有些东西还是要从github上找。

离线安装K3S需要下载的安装包:

1、K3s 的安装脚本(install.sh)      #下载匹配版本
2、K3s 的二进制文件(k3s)
3、K3s 依赖的镜像(k3s-airgap-images-amd64.tar)

三、K3S离线安装

1、官方参考文档

离线安装高可用k3s集群
https://docs.rancher.cn/docs/k3s/installation/airgap/_index

2、创建数据库

MariaDB [(none)]> create database k3sdb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
MariaDB [(none)]> grant usage on k3sdb.* to 'k3suser'@'%' identified by 'hz310012' with grant option;
MariaDB [(none)]> grant all privileges on k3sdb.* to 'k3suser'@'%';
MariaDB [(none)]> flush privileges;

3、执行 k3s 离线安装脚本

在两台master节点上都要执行离线安装k3s脚本

[root@rancher02 ~]# INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --docker --datastore-endpoint="mysql://k3suser:hz310012@tcp(172.16.4.133:3306)/k3sdb"' ./install.sh

4、修改 k3s.service 配置文件

k3s服务启动报错需要修改/etc/systemd/system/k3s.service配置文件,把k3s.service文件数据库连接串中的括号前的转义符删除后再重启k3s服务。

[root@rancher02 ~]# vim /etc/systemd/system/k3s.service
[root@rancher02 ~]# systemctl daemon-reload
[root@rancher02 ~]# systemctl start k3s

5、安装后两节点的状态

(1)在两台master节点上查看主机,显示如下:

[root@rancher01 ~]# kubectl get node
NAME                     STATUS   ROLES    AGE   VERSION
rancher01.techzsun.com   Ready    master   35m   v1.19.5+k3s2
rancher02.techzsun.com   Ready    master   31m   v1.19.5+k3s2

(2)在两台master节点查看pod状态如下:

[root@rancher01 ~]# kubectl get pod -A
NAMESPACE     NAME                                     READY   STATUS      RESTARTS   AGE
kube-system   local-path-provisioner-7ff9579c6-m9ql4   1/1     Running     0          36m
kube-system   helm-install-traefik-4tcf4               0/1     Completed   0          36m
kube-system   metrics-server-7b4f8b595-slbjm           1/1     Running     0          36m
kube-system   svclb-traefik-qpkxv                      2/2     Running     0          36m
kube-system   coredns-66c464876b-rbdjw                 1/1     Running     0          36m
kube-system   traefik-5dd496474-6l8n7                  1/1     Running     0          36m
kube-system   svclb-traefik-sschc                      2/2     Running     0          32m
[root@rancher01 ~]#

(3) 在两台master节点查看镜像如下:

[root@rancher01 ~]# crictl images
IMAGE                                      TAG                 IMAGE ID            SIZE
docker.io/rancher/coredns-coredns          1.6.9               4e797b3234604       43.3MB
docker.io/rancher/klipper-helm             v0.3.0              5c7bd28900147       148MB
docker.io/rancher/klipper-lb               v0.1.2              897ce3c5fc8ff       6.46MB
docker.io/rancher/library-busybox          1.31.1              1c35c44120825       1.44MB
docker.io/rancher/library-traefik          1.7.19              aa764f7db3051       86.6MB
docker.io/rancher/local-path-provisioner   v0.0.14             e422121c9c5f9       42MB
docker.io/rancher/metrics-server           v0.3.6              9dd718864ce61       41.2MB
docker.io/rancher/pause

(4)用 crictl ps -a 命令查看master01

[root@rancher01 ~]# crictl ps -a 
CONTAINER       IMAGE           CREATED          STATE      NAME                      ATTEMPT     POD ID
1cedabd31b3d6   9dd718864ce61   39 minutes ago   Running    metrics-server            0           7bf664a823a07
356dcc3aa3e4e   4e797b3234604   39 minutes ago   Running    coredns                   0           ebac6c5021b7c
edcc04f6d0677   aa764f7db3051   39 minutes ago   Running    traefik                   0           607f0e2abbc35
90ea185ff20a8   897ce3c5fc8ff   39 minutes ago   Running    lb-port-443               0           ff83f3dea537c
38ca22a82212c   897ce3c5fc8ff   39 minutes ago   Running    lb-port-80                0           ff83f3dea537c
edb6293239ab2   5c7bd28900147   39 minutes ago   Exited     helm                      0           a9621c3afc117
6d668bd41c2fc   e422121c9c5f9   40 minutes ago   Running    local-path-provisioner    0           08ab7354bfa38
[root@rancher01 ~]#

用 crictl ps -a 命令查看master02

[root@rancher02 ~]# crictl ps -a
CONTAINER           IMAGE               CREATED             STATE               NAME                ATTEMPT             POD ID
80fe832b808de       897ce3c5fc8ff       36 minutes ago      Running             lb-port-443         0                   ced33b0c3d289
2651c3c41c9e3       897ce3c5fc8ff       36 minutes ago      Running             lb-port-80          0                   ced33b0c3d289
[root@rancher02 ~]#

至此,离线高可用k3s集群安装完成。
如果需要重新安装,按下列方法清理节点:

1、执行下k3s的卸载脚本;
2、删除掉对应的数据库实例,或者下次安装k3s时候配一个其他的新的数据库实例;
3、执行rancher官网的清理脚本,保证相关的容器都清理掉
4、在节点执行 rm -rf /var/lib/rancher, rm -rf /etc/rancher 这两个目录,
5、重新安装。

四、离线安装 Rancher

1、离线安装包下载

https://github.com/rancher/rancher/tree/v2.5.5
版本信息
镜像
    rancher/rancher:v2.5.5
    rancher/rancher-agent:v2.5.5
工具
    cli - v2.4.10
    rke - v1.2.4
Kubernete 版本
    1.19.6(默认版本)
    1.18.14
    1.17.16

参考资料
一文搞定全场景K3s离线安装 作者:王海龙,Rancher中国社区技术经理
https://www.cnblogs.com/k3s2019/p/14339547.html
https://docs.rancher.cn/docs/k3s/installation/airgap/_index/

Rancher On K3s 高可用架构部署
https://www.cnblogs.com/shangmo/p/14337131.html

https://docs.rancher.cn/docs/octopus/quick-start/_index/#1-%E4%BD%BF%E7%94%A8-k3d-%E6%90%AD%E5%BB%BA-k3s-%E9%9B%86%E7%BE%A4%E5%8F%AF%E9%80%89

Arm离线安装踩坑过程
https://gitlab.agileserve.org.cn:8001/ucas-cod-advanced/automatics_ops/-/tree/master/ARM-K3s

RKE URL: https://github.com/rancher/rke/releases/tag/v1.2.5

其它:
centos离线安装k3s集群———————-非高可用?
https://blog.csdn.net/qq_21816375/article/details/105600588

使用k3sup快速部署高可用K3s集群
https://www.w3xue.com/exp/article/20205/86710.html

保姆级教程!使用k3d实现K3s高可用
https://jishuin.proginn.com/p/763bfbd380f4

https://github.com/alexellis/k3sup
https://github.com/alexellis/k3sup/releases