本文由 [编码如写诗] 原创编写,作者天行,KubeSphere 社区经过授权转载。

KubeSphere V4 已经开源半年多,而且 v4.1.3 也已经出来了,修复了众多 bug。介于 V4 优秀的 Luban 架构,核心组件非常少,资源占用也显著降低,同时带来众多功能和便利性。我们决定与时俱进,使用 1.30+版本的 Kubernetes 和 v4 版本的 KubeSphere。

环境涉及软件版本信息

  • 服务器芯片: 海光 3350/兆芯开先 KX-5000
  • 操作系统:麒麟 V10 SP3
  • Containerd: 1.7.13
  • Kubernetes:v1.31.8
  • KubeSphere:v4.1.3
  • KubeKey: v3.1.9
  • Docker: 24.0.9
  • DockerCompose: v2.26.1
  • Harbor: v2.10.1

服务器基本信息

[root@0003 Kubernetes-init]# uname -a
Linux node1 4.19.90-52.22.v2207.ky10.x86_64 #1 SMP Tue Mar 14 12:19:10 CST 2023 x86_64 x86_64 x86_64 GNU/Linux

[root@0003 Kubernetes-init]# cat /etc/os-release
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Lance)"
ID="Kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Lance)"
ANSI_COLOR="0;31"

1. 前提条件

参考如下示例准备至少三台主机

<font style="color:rgb(66, 75, 93);">主机名</font><font style="color:rgb(66, 75, 93);">IP</font><font style="color:rgb(66, 75, 93);">架构</font><font style="color:rgb(66, 75, 93);">OS</font><font style="color:rgb(66, 75, 93);">用途</font>
<font style="color:rgb(66, 75, 93);">node</font><font style="color:rgb(66, 75, 93);">192.168.3.249</font><font style="color:rgb(66, 75, 93);">x86_64</font><font style="color:rgb(66, 75, 93);">Ubuntu24.04</font><font style="color:rgb(66, 75, 93);">联网主机,用于制作离线包</font>
<font style="color:rgb(66, 75, 93);">master</font><font style="color:rgb(66, 75, 93);">192.168.85.138</font><font style="color:rgb(66, 75, 93);">x86_64</font><font style="color:rgb(66, 75, 93);">麒麟 V10</font><font style="color:rgb(66, 75, 93);">离线环境主节点</font>
<font style="color:rgb(66, 75, 93);">node1</font><font style="color:rgb(66, 75, 93);">192.168.85.139</font><font style="color:rgb(66, 75, 93);">x86_64</font><font style="color:rgb(66, 75, 93);">麒麟 V10</font><font style="color:rgb(66, 75, 93);">离线环境的工作节点和镜像仓库节点</font>

2. 构建离线包

在 node 可联网节点上操作

2.1 下载 KubeKey

curl -sSL https://get-KubeKey.kubesphere.io | sh -

2.2 编辑 manifest 文件

vi manifest-sample.yaml
apiVersion: KubeKey.kubesphere.io/v1alpha2
kind: Manifest
metadata:
  name: sample
spec:
  arches:
  - amd64
  operatingSystems: []
  kubernetesDistributions:
  - type: kubernetes
    version: v1.31.8
  components:
    Helm:
      version: v3.14.3
    cni:
      version: v1.2.0
    etcd:
      version: v3.5.13
    containerRuntimes:
    - type: Docker
      version: 24.0.9
    - type: containerd
      version: 1.7.13
    calicoctl:
      version: v3.27.4
    crictl:
      version: v1.29.0
    Docker-registry:
      version: "2"
    harbor:
      version: v2.10.1
    Docker-compose:
      version: v2.26.1
  images:
  - registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.9
  - registry.cn-beijing.aliyuncs.com/kubesphereio/kube-apiserver:v1.31.8
  - registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controller-manager:v1.31.8
  - registry.cn-beijing.aliyuncs.com/kubesphereio/kube-scheduler:v1.31.8
  - registry.cn-beijing.aliyuncs.com/kubesphereio/kube-proxy:v1.31.8
  - registry.cn-beijing.aliyuncs.com/kubesphereio/coredns:1.9.3
  - registry.cn-beijing.aliyuncs.com/kubesphereio/Kubernetes-dns-node-cache:1.22.20
  - registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controllers:v3.27.4
  - registry.cn-beijing.aliyuncs.com/kubesphereio/cni:v3.27.4
  - registry.cn-beijing.aliyuncs.com/kubesphereio/node:v3.27.4
  - registry.cn-beijing.aliyuncs.com/kubesphereio/pod2daemon-flexvol:v3.27.4
  # ks
  - swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/ks-extensions-museum:v1.1.2
  - swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/ks-controller-manager:v4.1.3
  - swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/ks-apiserver:v4.1.3
  - swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/ks-console:v4.1.3
  - swr.cn-southwest-2.myhuaweicloud.com/ks/kubesphere/kubectl:v1.27.16
  registry:
    auths: {}

2.3 导出离线制品

export KKZONE=cn
./KubeKey artifact export -m manifest-sample.yaml -o artifact-Kubernetes-1318-ks413.tar.gz

2.4 下载 KubeSphere Core Helm Chart

安装 Helm

curl https://raw.githubusercontent.com/Helm/Helm/main/scripts/get-Helm-3 | bash

下载 KubeSphere Core Helm Chart

VERSION=1.1.3     # Chart 版本
Helm fetch https://charts.kubesphere.io/main/ks-core-${VERSION}.tgz

3. 离线部署准备

3.1 移除麒麟系统自带的 Podman

Podman 是麒麟系统自带的容器引擎,容易与 Docker 冲突。不卸载的话后续 coredns/nodelocaldns 会受影响无法启动以及各种 Docker 权限问题。这里直接卸载,以便后续使用 Docker,所有节点执行

yum remove Podman

3.2 将安装包拷贝至离线环境

将下载的 KubeKey 、制品 artifact 、脚本和导出的镜像通过 U 盘、堡垒机 SSH 等介质拷贝至master 主节点

后续无特殊说明,只在 master 节点操作。

3.3 安装 Kubernetes 依赖包

所有节点执行,上传 Kubernetes-init-KylinV10.tar.gz 解压后执行 install.sh

3.4 修改配置文件

主要修改相关节点和 harbor 信息

vi config-sample.yaml
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: master, address: 192.168.85.138, internalAddress: 192.168.85.138, user: root, password: "123456"}
  - {name: node1, address: 192.168.85.139, internalAddress: 192.168.85.139, user: root, password: "123456"}
  roleGroups:
    etcd:
    - master
    control-plane:
    - master
    worker:
    - node1
    registry:
    - node1
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.31.8
    clusterName: cluster.local
    autoRenewCerts: true
    containerManager: containerd
  etcd:
    type: KubeKey
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
    multusCNI:
      enabled: false
  registry:
    type: harbor
    registryMirrors: []
    insecureRegistries: []
    privateRegistry: "dockerhub.KubeKey.local"
    namespaceOverride: "kubesphereio"
    auths: # if Docker add by `Docker login`, if containerd append to `/etc/containerd/config.toml`
      "dockerhub.KubeKey.local":
        username: "admin"
        password: Harbor@123 #此处可自定义,kk3.1.8 新特性
        skipTLSVerify: true # Allow contacting registries over HTTPS with failed TLS verification.
        plainHTTP: false # Allow contacting registries over HTTP.
        certsPath: "/etc/Docker/certs.d/dockerhub.KubeKey.local"
  addons: []

3.5 创建镜像仓库

./KubeKey init registry -f config-sample.yaml -a artifact-Kubernetes-1318-ks413.tar.gz

3.6 创建 harbor 项目

<font style="background-color:rgb(255,245,235);">说明:</font>

<font style="background-color:rgb(255,245,235);">由于 Harbor 项目存在访问控制(RBAC)的限制,即只有指定角色的用户才能执行某些操作。如果您未创建项目,则镜像不能被推送到 Harbor。Harbor 中有两种类型的项目:</font>

  • <font style="background-color:rgb(255,245,235);">公共项目(Public):任何用户都可以从这个项目中拉取镜像。</font>
  • <font style="background-color:rgb(255,245,235);">私有项目(Private):只有作为项目成员的用户可以拉取镜像。</font>

<font style="background-color:rgb(255,245,235);">Harbor 管理员账号:</font><font style="background-color:rgb(255,245,235);">admin</font><font style="background-color:rgb(255,245,235);">,密码:</font><font style="background-color:rgb(255,245,235);">Harbor@123</font><font style="background-color:rgb(255,245,235);">。密码同步使用配置文件中的对应 password</font>

<font style="background-color:rgb(255,245,235);">harbor 安装文件在 </font><font style="background-color:rgb(255,245,235);">/opt/harbor</font><font style="background-color:rgb(255,245,235);"> 目录下,可在该目录下对 harbor 进行运维。</font>

vi create_project_harbor.sh
#!/usr/bin/env bash

url="https://dockerhub.KubeKey.local"  # 或修改为实际镜像仓库地址
user="admin"
passwd="Harbor@123"

harbor_projects=(
        ks
        kubesphere
        kubesphereio
)

for project in "${harbor_projects[@]}"; do
    echo "creating $project"
    curl -u "${user}:${passwd}" -X POST -H "Content-Type: application/json" "${url}/api/v2.0/projects" -d "{ \"project_name\": \"${project}\", \"public\": true}" -k  # 注意在 curl 命令末尾加上 -k
done

创建 Harbor 项目

chmod +x create_project_harbor.sh

./create_project_harbor.sh

验证

4. 安装 Kubernetes

执行以下命令创建 Kubernetes 集群:

./KubeKey create cluster -f config-sample.yaml -a artifact-Kubernetes-1318-ks413.tar.gz --with-local-storage

等待大概两分钟左右看到成功消息

验证

5. 安装 KubeSphere

Helm upgrade --install -n kubesphere-system --create-namespace ks-core ks-core-1.1.5.tgz \
     --set global.imageRegistry=dockerhub.KubeKey.local/ks \
     --set extension.imageRegistry=dockerhub.KubeKey.local/ks \
     --set ksExtensionRepository.image.tag=v1.1.5 \
     --debug \
     --wait

等待大概 30 秒左右看到成功消息

6. 验证

登录页面

初次登录需要换密码,如果不想换也可以继续填写P@88w0rd,不过建议更换

首页

集群节点版本信息

概览

7. 说明

本文由 [编码如写诗-天行 1st] 原创编写,有任何问题可添加作者微信 [sd_zdhr] 获取协助。转载请获取作者同意。

关于作者:

  • 主要从事后端开发,兼具前端、运维及全栈工程师,热爱GolangDockerkubernetesKubeSphere
  • 信创服务器Kubernetes&KubeSphere布道者、KubeSphere离线部署布道者
  • 公众号:编码如写诗,作者:天行 1st,微信:sd_zdhr
本文由博客一文多发平台 OpenWrite 发布!

KubeSphere
127 声望61 粉丝

KubeSphere 是一个开源的以应用为中心的容器管理平台,支持部署在任何基础设施之上,并提供简单易用的 UI,极大减轻日常开发、测试、运维的复杂度,旨在解决 Kubernetes 本身存在的存储、网络、安全和易用性等痛...