website/content/zh/docs/v3.3/installing-on-linux/on-premises/install-kubesphere-and-k3s.md
Bettygogo2021 0ea050a2c3 Fix: change kk version to 3.0.7
Signed-off-by: Bettygogo2021 <bettygogo@kubesphere.io>
2023-04-04 17:39:52 +08:00

5.5 KiB
Raw Blame History

title keywords description linkTitle weight
部署 K3s 和 KubeSphere Kubernetes, KubeSphere, K3s 了解如何使用 KubeKey 安装 K3s 和 KubeSphere。 部署 K3s 和 KubeSphere 3530

K3s 是专为物联网和边缘计算打造的轻量级 Kubernetes 发行版,最大程度上剔除了外部依赖项。它打包为单个二进制文件,减少了搭建 Kubernetes 集群所需的依赖项和步骤。

您可以使用 KubeKey 同时安装 K3s 和 KubeSphere也可以将 KubeSphere 部署在现有的 K3s 集群上。

{{< notice note >}}

目前,由于功能尚未充分测试,在 K3s 上部署 KubeSphere 仅用于测试和开发。

{{</ notice >}}

准备工作

  • 有关安装 K3s 的准备工作的更多信息,请参阅 K3s 文档
  • 取决于您的网络环境,您可能需要配置防火墙规则和端口转发规则。有关更多信息,请参见端口要求

步骤 1下载 KubeKey

执行以下步骤下载 KubeKey

{{< tabs >}}

{{< tab "如果您能正常访问 GitHub/Googleapis" >}}

GitHub Release Page 下载 KubeKey 或直接运行以下命令:

curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -

{{</ tab >}}

{{< tab "如果您访问 GitHub/Googleapis 受限" >}}

首先运行以下命令,以确保您从正确的区域下载 KubeKey。

export KKZONE=cn

运行以下命令来下载 KubeKey

curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -

{{< notice note >}}

下载 KubeKey 之后,如果您将其转移到访问 Googleapis 受限的新机器上,请务必再次运行 export KKZONE=cn,然后继续执行以下步骤。

{{</ notice >}}

{{</ tab >}}

{{</ tabs >}}

{{< notice note >}}

通过以上的命令可以下载 KubeKey 的最新版本。请注意,更早版本的 KubeKey 无法下载 K3s。

{{</ notice >}}

执行以下命令为 kk 文件增加执行权限:

chmod +x kk

步骤 2创建集群

  1. 执行以下命令为集群创建一个配置文件:

    ./kk create config --with-kubernetes v1.21.4-k3s --with-kubesphere v3.3.2
    

    {{< notice note >}}

    • KubeKey v3.0.7 支持安装 K3s v1.21.4。

    • 您可以在以上命令中使用 -f--file 参数指定配置文件的路径和名称。如未指定路径和名称KubeKey 将默认在当前目录下创建 config-sample.yaml 配置文件。

    {{</ notice >}}

  2. 执行以下命令编辑配置文件(以下以默认配置文件名为例):

    vi config-sample.yaml
    
    ...
    metadata:
      name: sample
    spec:
      hosts:
      - {name: master, address: 192.168.0.2, internalAddress: 192.168.0.2, user: ubuntu, password: Testing123}
      - {name: node1, address: 192.168.0.3, internalAddress: 192.168.0.3, user: ubuntu, password: Testing123}
      - {name: node2, address: 192.168.0.4, internalAddress: 192.168.0.4, user: ubuntu, password: Testing123}
      roleGroups:
        etcd:
        - master
        control-plane:
        - master
        worker:
        - node1
        - node2
      controlPlaneEndpoint:
        domain: lb.kubesphere.local
        address: ""
        port: 6443
      kubernetes:
        version: v1.21.4-k3s
        imageRepo: kubesphere
        clusterName: cluster.local
      network:
        plugin: calico
        kubePodsCIDR: 10.233.64.0/18
        kubeServiceCIDR: 10.233.0.0/18
      registry:
        registryMirrors: []
        insecureRegistries: []
      addons: []
    ...
    

    {{< notice note >}}

    有关配置文件中每个字段的更多信息,请参阅示例文件

    {{</ notice >}}

  3. 保存文件并执行以下命令安装 K3s 和 KubeSphere

    ./kk create cluster -f config-sample.yaml
    
  4. 安装完成后,可运行以下命令查看安装日志:

    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f
    

    如果显示如下信息则安装成功:

    #####################################################
    ###              Welcome to KubeSphere!           ###
    #####################################################
    
    Console: http://192.168.0.2:30880
    Account: admin
    Password: P@88w0rd
    
    NOTES
      1. After you log into the console, please check the
         monitoring status of service components in
         "Cluster Management". If any service is not
         ready, please wait patiently until all components
         are up and running.
      2. Please change the default password after login.
    
    #####################################################
    https://kubesphere.io             20xx-xx-xx xx:xx:xx
    #####################################################
    
  5. 从安装日志的 ConsoleAccountPassword 参数分别获取 KubeSphere Web 控制台的地址、系统管理员用户名和系统管理员密码,并使用 Web 浏览器登录 KubeSphere Web 控制台。

    {{< notice note >}}

    您可以在安装后启用 KubeSphere 的可插拔组件,但由于在 KubeSphere 上部署 K3s 目前处于测试阶段,某些功能可能不兼容。

    {{</ notice >}}