离线安装高可用k3s集群
<h1>一、安装前准备</h1>
<p>基础环境准备</p>
<h1>二、K3S离线包下载</h1>
<h2>1、查看需要下载的安装包版本匹配情况</h2>
<p><a href="https://rancher.com/support-maintenance-terms/all-supported-versions/rancher-v2.5.5/">https://rancher.com/support-maintenance-terms/all-supported-versions/rancher-v2.5.5/</a>
<img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/a4fabe45fda137667eef1dd894fd94c6" alt="" /></p>
<h2>2、下载离线安装包</h2>
<p>k3s URL:
<a href="https://github.com/k3s-io/k3s/releases">https://github.com/k3s-io/k3s/releases</a>
找到v1.19.5-k3s+2版本的URL:
<a href="https://github.com/k3s-io/k3s/releases/tag/v1.19.5%2Bk3s2">https://github.com/k3s-io/k3s/releases/tag/v1.19.5%2Bk3s2</a></p>
<p>k3s 国内 URL:
<a href="http://mirror.cnrancher.com">http://mirror.cnrancher.com</a>
国内会少一些东西。有些东西还是要从github上找。</p>
<p>离线安装K3S需要下载的安装包:</p>
<pre><code class="language-bash">1、K3s 的安装脚本(install.sh) #下载匹配版本
2、K3s 的二进制文件(k3s)
3、K3s 依赖的镜像(k3s-airgap-images-amd64.tar)</code></pre>
<h1>三、K3S离线安装</h1>
<h2>1、官方参考文档</h2>
<p>离线安装高可用k3s集群
<a href="https://docs.rancher.cn/docs/k3s/installation/airgap/_index">https://docs.rancher.cn/docs/k3s/installation/airgap/_index</a></p>
<h2>2、创建数据库</h2>
<pre><code class="language-bash">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;</code></pre>
<h2>3、执行 k3s 离线安装脚本</h2>
<p>在两台master节点上都要执行离线安装k3s脚本</p>
<pre><code class="language-bash">[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</code></pre>
<h2>4、修改 k3s.service 配置文件</h2>
<p>k3s服务启动报错需要修改/etc/systemd/system/k3s.service配置文件,把k3s.service文件数据库连接串中的括号前的转义符删除后再重启k3s服务。</p>
<pre><code class="language-bash">[root@rancher02 ~]# vim /etc/systemd/system/k3s.service
[root@rancher02 ~]# systemctl daemon-reload
[root@rancher02 ~]# systemctl start k3s</code></pre>
<h2>5、安装后两节点的状态</h2>
<p>(1)在两台master节点上查看主机,显示如下:</p>
<pre><code class="language-bash">[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</code></pre>
<p>(2)在两台master节点查看pod状态如下:</p>
<pre><code class="language-bash">[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 ~]#</code></pre>
<p>(3) 在两台master节点查看镜像如下:</p>
<pre><code class="language-bash">[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</code></pre>
<p>(4)用 crictl ps -a 命令查看master01</p>
<pre><code class="language-bash">[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 ~]#</code></pre>
<p>用 crictl ps -a 命令查看master02</p>
<pre><code class="language-bash">[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 ~]#</code></pre>
<p><code>至此,离线高可用k3s集群安装完成。</code>
如果需要重新安装,按下列方法清理节点:</p>
<pre><code class="language-bash">1、执行下k3s的卸载脚本;
2、删除掉对应的数据库实例,或者下次安装k3s时候配一个其他的新的数据库实例;
3、执行rancher官网的清理脚本,保证相关的容器都清理掉
4、在节点执行 rm -rf /var/lib/rancher, rm -rf /etc/rancher 这两个目录,
5、重新安装。</code></pre>
<h1>四、离线安装 Rancher</h1>
<p>1、离线安装包下载</p>
<pre><code class="language-bash">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</code></pre>
<p>参考资料
一文搞定全场景K3s离线安装 作者:王海龙,Rancher中国社区技术经理
<a href="https://www.cnblogs.com/k3s2019/p/14339547.html">https://www.cnblogs.com/k3s2019/p/14339547.html</a>
<a href="https://docs.rancher.cn/docs/k3s/installation/airgap/_index/">https://docs.rancher.cn/docs/k3s/installation/airgap/_index/</a></p>
<p>Rancher On K3s 高可用架构部署
<a href="https://www.cnblogs.com/shangmo/p/14337131.html">https://www.cnblogs.com/shangmo/p/14337131.html</a></p>
<p><a href="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">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</a></p>
<p>Arm离线安装踩坑过程
<a href="https://gitlab.agileserve.org.cn:8001/ucas-cod-advanced/automatics_ops/-/tree/master/ARM-K3s">https://gitlab.agileserve.org.cn:8001/ucas-cod-advanced/automatics_ops/-/tree/master/ARM-K3s</a></p>
<p>RKE URL: <a href="https://github.com/rancher/rke/releases/tag/v1.2.5">https://github.com/rancher/rke/releases/tag/v1.2.5</a></p>
<p>其它:
centos离线安装k3s集群---------------非高可用?
<a href="https://blog.csdn.net/qq_21816375/article/details/105600588">https://blog.csdn.net/qq_21816375/article/details/105600588</a></p>
<p>使用k3sup快速部署高可用K3s集群
<a href="https://www.w3xue.com/exp/article/20205/86710.html">https://www.w3xue.com/exp/article/20205/86710.html</a></p>
<p>保姆级教程!使用k3d实现K3s高可用
<a href="https://jishuin.proginn.com/p/763bfbd380f4">https://jishuin.proginn.com/p/763bfbd380f4</a></p>
<p><a href="https://github.com/alexellis/k3sup">https://github.com/alexellis/k3sup</a>
<a href="https://github.com/alexellis/k3sup/releases">https://github.com/alexellis/k3sup/releases</a></p>