zoukankan      html  css  js  c++  java
  • k8s 集群中安装 kubesphere v3.1.1

    k8s 集群中安装 kubesphere v3.1.1

    kubesphere 可以直接在裸机 linux 安装,也可在已经存在的 k8s 集群中安装,本文只介绍在存在的 k8s 集群中安装 kubesphere 。

    什么是 KubeSphere

    KubeSphere 是在 Kubernetes 之上构建的面向云原生应用的分布式操作系统,完全开源,支持多云与多集群管理,提供全栈的 IT 自动化运维能力,简化企业的 DevOps 工作流。它的架构可以非常方便地使第三方应用与云原生生态组件进行即插即用 (plug-and-play) 的集成。

    作为全栈的多租户容器平台,KubeSphere 提供了运维友好的向导式操作界面,帮助企业快速构建一个强大和功能丰富的容器云平台。KubeSphere 为用户提供构建企业级 Kubernetes 环境所需的多项功能,例如多云与多集群管理、Kubernetes 资源管理、DevOps、应用生命周期管理、微服务治理(服务网格)、日志查询与收集、服务与网络、多租户管理、监控告警、事件与审计查询、存储管理、访问权限控制、GPU 支持、网络策略、镜像仓库管理以及安全管理等。

    KubeSphere 还开源了 KubeKey 帮助企业一键在公有云或数据中心快速搭建 Kubernetes 集群,提供单节点、多节点、集群插件安装,以及集群升级与运维。

    开发运维友好

    KubeSphere 为用户屏蔽了基础设施底层复杂的技术细节,帮助企业在各类基础设施之上无缝地部署、更新、迁移和管理现有的容器化应用。通过这种方式,KubeSphere 使开发人员能够专注于应用程序开发,使运维团队能够通过企业级可观测性功能和故障排除机制、统一监控和日志查询、存储和网络管理,以及易用的 CI/CD 流水线等来加快 DevOps 自动化工作流程和交付流程等。

    支持在任意平台运行 KubeSphere

    作为一个灵活的轻量级容器 PaaS 平台,KubeSphere 对不同云生态系统的支持非常友好,因为它对原生 Kubernetes 本身没有任何的侵入 (Hack)。换句话说,KubeSphere 可以部署并运行在任何基础架构以及所有版本兼容的 Kubernetes 集群之上,包括虚拟机、物理机、数据中心、公有云和混合云等。

    您可以选择在公有云和托管 Kubernetes 集群(例如阿里云、AWS、青云QingCloud、腾讯云、华为云等)上安装 KubeSphere,还可以导入和纳管已有的 Kubernetes 集群。

    KubeSphere 可以在不修改用户当前的资源或资产、不影响其业务的情况下部署在现有的 Kubernetes 平台上。有关更多信息,请参见在 Linux 上安装和在 Kubernetes 上安装。

    完全开源

    借助开源的模式,KubeSphere 社区驱动着开发工作以开放的方式进行。KubeSphere 100% 开源免费,已大规模服务于社区用户,广泛地应用在以 Docker 和 Kubernetes 为中心的开发、测试及生产环境中,大量服务平稳地运行在 KubeSphere 之上。您可在 GitHub 上找到所有源代码、文档和讨论,所有主要的开源项目介绍可以在开源项目列表中找到。

    云原生 Landscape

    KubeSphere 是 CNCF 基金会成员并且通过了 Kubernetes 一致性认证,进一步丰富了 CNCF 云原生的生态。

    前置条件

    集群中有默认 storage class,可以使用本地存储,NFS,CEPH,glusterfs 等

    本地存储 yaml 参考:

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: local-storage
    provisioner: kubernetes.io/no-provisioner
    volumeBindingMode: WaitForFirstConsumer
    

    配置为默认 sc

    kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
    
    • storageclass.kubernetes.io/is-default-class 设置为 false 即可去除默认

    查看已经运行ok

    kubectl get sc
    

    创建 docker hub 镜像仓库

    可以使用 Harbor 或者其他任意私有镜像仓库。本教程以 Docker 仓库作为示例,并使用自签名证书(如果已有私有镜像仓库,可以跳过这一步)。

    创建自签证书

    执行命令

    openssl req 
    -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key 
    -x509 -days 36500 -out certs/domain.crt
    

    当生成自己的证书时,请确保在字段 Common Name 中指定一个域名。例如,本示例中该字段被指定为 dockerhub.leffss.local

    启动 docker 仓库

    执行以下命令启动 Docker 仓库:

    docker run -d 
      --restart=always 
      --name registry 
      -v "$(pwd)"/certs:/certs 
      -v /mnt/registry:/var/lib/registry 
      -e REGISTRY_HTTP_ADDR=0.0.0.0:443 
      -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt 
      -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key 
      -p 443:443 
      registry:2
    
    • registry:2 部署的仓库可以添加 http 验证(使用 docker login 登录)

    备注:Docker 使用 /var/lib/docker 作为默认路径来存储所有 Docker 相关文件(包括镜像)。建议您添加附加存储卷,分别给 /var/lib/docker 和 /mnt/registry(映射给 docker hub) 挂载至少 100G。

    配置仓库

    在需要访问仓库的 docker 主机 /etc/hosts 添加一条记录:

    # docker registry
    192.168.223.151 dockerhub.leffss.local
    

    执行:

    mkdir -p  /etc/docker/certs.d/dockerhub.leffss.local
    mv domain.crt ca.crt
    mv ca.crt /etc/docker/certs.d/dockerhub.leffss.local/
    
    • 目录和 docker hub 的域名保持一致
    • domain.crt 为前面搭建仓库时生成的证书文件
    • 如果是容器运行时使用的 containerd ,配置方法应该不一样,这里没作研究。

    测试

    docker pull busybox:1.28.3
    docker tag busybox:1.28.3 dockerhub.leffss.local/busybox:1.28.3
    docker push dockerhub.leffss.local/busybox:1.28.3
    
    docker rmi busybox:1.28.3
    docker rmi dockerhub.leffss.local/busybox:1.28.3
    
    docker pull dockerhub.leffss.local/busybox:1.28.3
    
    • 如果 hub 正常,整个过程应该不会报错

    准备安装镜像

    当在离线环境中安装 KubeSphere 时,需要事先准备一个包含所有必需镜像的镜像包。

    下载镜像清单文件 images-list.txt

    curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/images-list.txt
    

    该文件根据不同的模块列出了 ##+modulename 下的镜像。可以按照相同的规则把自己的镜像添加到这个文件中。

    下载 offline-installation-tool.sh

    curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/offline-installation-tool.sh
    

    根据 images-list.txt 下载镜像

    mkdir kubesphere-images
    sh offline-installation-tool.sh -s -l images-list.txt -d ./kubesphere-images
    

    可以根据需要选择拉取的镜像。例如,如果已经有一个 Kubernetes 集群了,则可以在 images-list.text 中删除 ##k8s-images 和在它下面的相关镜像。

    推送镜像至私有仓库

    将打包的镜像文件传输至本地仓库

    ./offline-installation-tool.sh -l images-list.txt -d ./kubesphere-images -r dockerhub.leffss.local
    
    • 命令中的域名是 dockerhub.leffss.local。请确保使用自己仓库的地址。

    下载部署文件

    下载 cluster-configuration.yaml 和 kubesphere-installer.yaml

    curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml
    curl -L -O https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
    

    编辑 cluster-configuration.yaml 添加私有镜像仓库

    ...
    spec:
      persistence:
        storageClass: ""        # If there is no default StorageClass in your cluster, you need to specify an existing StorageClass here.
      authentication:
        jwtSecret: ""           # Keep the jwtSecret consistent with the Host Cluster. Retrieve the jwtSecret by executing "kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret" on the Host Cluster.
      local_registry: dockerhub.leffss.local        # Add your private registry address if it is needed.
    ...
    

    可以在该 YAML 文件中启用可插拔组件,体验 KubeSphere 的更多功能。有关详情,请参考后面启用可插拔组件。默认最小化安装。可以后面修改开启组件后,使用 kubectl apply -f cluster-configuration.yaml 生效。

    编辑 kubesphere-installer.yaml 将 ks-installer 替换为本地仓库的地址

        spec:
          serviceAccountName: ks-installer
          containers:
          - name: installer
            image: dockerhub.leffss.local/kubesphere/ks-installer:v3.1.1
            imagePullPolicy: "Always"
            resources:
    

    开始安装

    kubectl apply -f kubesphere-installer.yaml
    kubectl apply -f cluster-configuration.yaml
    

    验证安装

    安装完成后,会看到以下内容:

    #####################################################
    ###              Welcome to KubeSphere!           ###
    #####################################################
    
    Console: http://192.168.0.2:30880
    Account: admin
    Password: P@88w0rd
    
    NOTES:
      1. After logging into the console, please check the
         monitoring status of service components in
         the "Cluster Management". If any service is not
         ready, please wait patiently until all components
         are ready.
      2. Please modify the default password after login.
    
    #####################################################
    https://kubesphere.io             20xx-xx-xx xx:xx:xx
    #####################################################
    

    现在,可以通过 http://{IP}:30880 使用默认帐户和密码 admin/P@88w0rd 访问 KubeSphere 的 Web 控制台。

    启用可插拔组件

    从 2.1.0 版本开始,KubeSphere 解耦了一些核心功能组件。这些组件设计成了可插拔式,这样可以在安装之前或之后启用它们。如果不启用它们,KubeSphere 会默认以最小化进行安装部署。

    不同的可插拔组件部署在不同的命名空间中。可以根据需求启用任意组件。强烈建议安装这些可插拔组件来深度体验 KubeSphere 提供的全栈特性和功能。

    有关如何启用每个组件的更多信息,请参见本章的各个教程。

    各组件资源要求

    在启用可插拔组件之前,请确保环境中有足够的资源,具体参见下表。否则,可能会因为缺乏资源导致组件崩溃。

    CPU 和内存的资源请求和限制均指单个副本的要求。

    KubeSphere 监控系统

    命名空间 kubesphere-monitoring-system kubesphere-monitoring-system kubesphere-monitoring-system
    子组件 2 x Prometheus 3 x Alertmanager Notification Manager
    CPU 请求 100 m 10 m 100 m
    CPU 限制 4 core 500 m
    内存请求 400 MiB 30 MiB 20 MiB
    内存限制 8 GiB 1 GiB
    安装 必需 必需 必需
    备注 Prometheus 的内存消耗取决于集群大小。8 GiB 可满足 200 个节点/16,000 个 Pod 的集群规模。

    KubeSphere 监控系统不是可插拔组件,会默认安装。它与其他组件(例如日志系统)紧密关联,因此将其资源请求和限制也列在本页中,供您参考。

    KubeSphere 应用商店

    命名空间 openpitrix-system
    CPU 请求 0.3 core
    CPU 限制
    内存请求 300 MiB
    内存限制
    安装 可选
    备注 提供应用商店进行应用生命周期管理。建议安装。

    KubeSphere DevOps 系统

    命名空间 kubesphere-devops-system kubesphere-devops-system
    安装模式 All-in-One 安装 多节点安装
    CPU 请求 34 m 0.47 core
    CPU 限制
    内存请求 2.69 G 8.6 G
    内存限制
    安装 可选 可选
    备注 提供一站式 DevOps 解决方案,包括 Jenkins 流水线、B2I 和 S2I。 其中一个节点的内存必须大于 8 G。

    KubeSphere 日志系统

    命名空间 kubesphere-logging-system kubesphere-logging-system kubesphere-logging-system kubesphere-logging-system
    子组件 3 x Elasticsearch fluent bit kube-events kube-auditing
    CPU 请求 50 m 20 m 90 m 20 m
    CPU 限制 1 core 200 m 900 m 200 m
    内存请求 2 G 50 MiB 120 MiB 50 MiB
    内存限制 100 MiB 1200 MiB 100 MiB
    安装 可选 必需 可选 可选
    备注 可选组件,用于存储日志数据。不建议在生产环境中使用内置 Elasticsearch。 日志收集代理。启用日志系统后,它是必需组件。 Kubernetes 事件收集、过滤、导出和告警。 Kubernetes 和 KubeSphere 审计日志收集、过滤和告警。

    KubeSphere 告警和通知

    命名空间 kubesphere-alerting-system
    CPU 请求 0.08 core
    CPU 限制
    内存请求 80 M
    内存限制
    安装 可选
    备注 告警和通知需要同时启用。

    KubeSphere 服务网格

    命名空间 istio-system
    CPU 请求 1 core
    CPU 限制
    内存请求 3.5 G
    内存限制
    安装 可选
    备注 支持灰度发布策略、流量拓扑、流量管理和分布式链路追踪。

    KubeSphere 应用商店

    作为一个开源的、以应用为中心的容器平台,KubeSphere 在 OpenPitrix 的基础上,为用户提供了一个基于 Helm 的应用商店,用于应用生命周期管理。OpenPitrix 是一个开源的 Web 平台,用于打包、部署和管理不同类型的应用。KubeSphere 应用商店让 ISV、开发者和用户能够在一站式服务中只需点击几下就可以上传、测试、部署和发布应用。

    对内,KubeSphere 应用商店可以作为不同团队共享数据、中间件和办公应用的场所。对外,有利于设立构建和交付的行业标准。默认情况下,应用商店中内置了 17 个应用。启用该功能后,可以通过应用模板添加更多应用。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    openpitrix:
      store:
        enabled: true # 将“false”更改为“true”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 openpitrix,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    openpitrix:
      store:
        enabled: true # 将“false”更改为“true”。
    
    1. 您可以使用 Web Kubectl 工具执行以下命令来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    您可以通过点击控制台右下角的 找到 Web Kubectl 工具。

    验证

    在登录控制台后,如果能看到页面左上角的应用商店以及其中的 17 个内置应用,则说明安装成功。

    在多集群架构中使用应用商店

    在多集群架构中,一个 Host 集群(H 集群)管理所有 Member 集群(M 集群)。与 KubeSphere 中的其他组件不同,应用商店是所有集群(包括 H 集群和 M 集群)的全局应用程序池。只需要在 H 集群上启用应用商店,便可以直接在 M 集群上使用应用商店的相关功能(无论 M 集群是否启用应用商店),例如应用模板和应用仓库。

    但是,如果只在 M 集群上启用应用商店而没有在 H 集群上启用,将无法在多集群架构中的任何集群上使用应用商店。

    KubeSphere DevOps 系统

    基于 Jenkins 的 KubeSphere DevOps 系统是专为 Kubernetes 中的 CI/CD 工作流设计的,它提供了一站式的解决方案,帮助开发和运维团队用非常简单的方式构建、测试和发布应用到 Kubernetes。它还具有插件管理、Binary-to-Image (B2I)、Source-to-Image (S2I)、代码依赖缓存、代码质量分析、流水线日志等功能。

    DevOps 系统为用户提供了一个自动化的环境,应用可以自动发布到同一个平台。它还兼容第三方私有镜像仓库(如 Harbor)和代码库(如 GitLab/GitHub/SVN/BitBucket)。它为用户提供了全面的、可视化的 CI/CD 流水线,打造了极佳的用户体验,而且这种兼容性强的流水线能力在离线环境中非常有用。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    devops:
      enabled: true # 将“false”更改为“true”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 devops,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    devops:
      enabled: true # 将“false”更改为“true”。
    
    1. 您可以使用 Web Kubectl 工具执行以下命令来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    您可以通过点击控制台右下角的 找到 Web Kubectl 工具。

    验证

    方法一:进入服务组件,检查 DevOps 的状态。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n kubesphere-devops-system
    

    如果组件运行成功,输出结果如下:

    NAME                          READY   STATUS    RESTARTS   AGE
    ks-jenkins-5cbbfbb975-hjnll   1/1     Running   0          40m
    s2ioperator-0                 1/1     Running   0          41m
    

    KubeSphere 日志系统

    KubeSphere 为日志收集、查询和管理提供了一个强大的、全面的、易于使用的日志系统。它涵盖了不同层级的日志,包括租户、基础设施资源和应用。用户可以从项目、工作负载、Pod 和关键字等不同维度对日志进行搜索。与 Kibana 相比,KubeSphere 基于租户的日志系统中,每个租户只能查看自己的日志,从而可以在租户之间提供更好的隔离性和安全性。除了 KubeSphere 自身的日志系统,该容器平台还允许用户添加第三方日志收集器,如 Elasticsearch、Kafka 和 Fluentd。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    logging:
      enabled: true # 将“false”更改为“true”。
    

    默认情况下,如果启用了日志系统,ks-installer 将安装内置 Elasticsearch。对于生产环境,如果您想启用日志系统,强烈建议在 cluster-configuration.yaml 中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安装前提供以下信息后,ks-installer 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台。点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration。点击结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 logging,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    logging:
      enabled: true # 将“false”更改为“true”。
    

    默认情况下,如果启用了日志系统,将会安装内置 Elasticsearch。对于生产环境,如果您想启用日志系统,强烈建议在该 YAML 文件中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在文件中提供以下信息后,KubeSphere 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    
    1. 您可以使用 Web Kubectl 工具执行以下命令来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:进入服务组件,检查 Logging 的状态

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n kubesphere-logging-system
    

    如果组件运行成功,输出结果如下:

    NAME                                          READY   STATUS    RESTARTS   AGE
    elasticsearch-logging-data-0                  1/1     Running   0          87m
    elasticsearch-logging-data-1                  1/1     Running   0          85m
    elasticsearch-logging-discovery-0             1/1     Running   0          87m
    fluent-bit-bsw6p                              1/1     Running   0          40m
    fluent-bit-smb65                              1/1     Running   0          40m
    fluent-bit-zdz8b                              1/1     Running   0          40m
    fluentbit-operator-9b69495b-bbx54             1/1     Running   0          40m
    logsidecar-injector-deploy-667c6c9579-cs4t6   2/2     Running   0          38m
    logsidecar-injector-deploy-667c6c9579-klnmf   2/2     Running   0          38m
    

    KubeSphere 事件系统

    KubeSphere 事件系统使用户能够跟踪集群内部发生的事件,例如节点调度状态和镜像拉取结果。这些事件会被准确记录下来,并在 Web 控制台中显示具体的原因、状态和信息。要查询事件,用户可以快速启动 Web 工具箱,在搜索栏中输入相关信息,并有不同的过滤器(如关键字和项目)可供选择。事件也可以归档到第三方工具,例如 Elasticsearch、Kafka 或 Fluentd。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    events:
      enabled: true # 将“false”更改为“true”。
    

    对于生产环境,如果您想启用事件系统,强烈建议在 cluster-configuration.yaml 中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安装前提供以下信息后,ks-installer 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 events,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    events:
      enabled: true # 将“false”更改为“true”。
    

    默认情况下,如果启用了事件系统,将会安装内置 Elasticsearch。对于生产环境,如果您想启用事件系统,强烈建议在该 YAML 文件中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在文件中提供以下信息后,KubeSphere 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    
    1. 可以使用 Web Kubectl 工具执行以下命令来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:验证您可以使用右下角工具箱中的事件查询功能。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n kubesphere-logging-system
    

    如果组件运行成功,输出结果如下:

    NAME                                          READY   STATUS    RESTARTS   AGE
    elasticsearch-logging-data-0                  1/1     Running   0          155m
    elasticsearch-logging-data-1                  1/1     Running   0          154m
    elasticsearch-logging-discovery-0             1/1     Running   0          155m
    fluent-bit-bsw6p                              1/1     Running   0          108m
    fluent-bit-smb65                              1/1     Running   0          108m
    fluent-bit-zdz8b                              1/1     Running   0          108m
    fluentbit-operator-9b69495b-bbx54             1/1     Running   0          109m
    ks-events-exporter-5cb959c74b-gx4hw           2/2     Running   0          7m55s
    ks-events-operator-7d46fcccc9-4mdzv           1/1     Running   0          8m
    ks-events-ruler-8445457946-cl529              2/2     Running   0          7m55s
    ks-events-ruler-8445457946-gzlm9              2/2     Running   0          7m55s
    logsidecar-injector-deploy-667c6c9579-cs4t6   2/2     Running   0          106m
    logsidecar-injector-deploy-667c6c9579-klnmf   2/2     Running   0          106m
    

    KubeSphere 告警系统

    告警是可观测性的重要组成部分,与监控和日志密切相关。KubeSphere 中的告警系统与其主动式故障通知 (Proactive Failure Notification) 系统相结合,使用户可以基于告警策略了解感兴趣的活动。当达到某个指标的预定义阈值时,会向预先配置的收件人发出告警。因此,需要预先配置通知方式,包括邮件、Slack、钉钉、企业微信和 Webhook。有了功能强大的告警和通知系统,就可以迅速发现并提前解决潜在问题,避免业务受影响。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    alerting:
      enabled: true # 将“false”更改为“true”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 alerting,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    alerting:
      enabled: true # 将“false”更改为“true”。
    
    1. 可以使用 Web Kubectl 工具执行以下命令来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    如果您在集群管理页面可以看到告警消息和告警策略,说明安装成功,因为安装组件之后才会显示这两部分。

    KubeSphere 审计日志

    KubeSphere 审计日志系统提供了一套与安全相关并按时间顺序排列的记录,按顺序记录了与单个用户、管理人员或系统其他组件相关的活动。对 KubeSphere 的每个请求都会生成一个事件,然后写入 Webhook,并根据一定的规则进行处理。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    auditing:
      enabled: true # 将“false”更改为“true”。
    

    默认情况下,如果启用了审计功能,ks-installer 会安装内置 Elasticsearch。对于生产环境,如果您想启用审计功能,强烈建议在 cluster-configuration.yaml 中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。在安装前提供以下信息后,ks-installer 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 auditing,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    auditing:
      enabled: true # 将“false”更改为“true”。
    

    默认情况下,如果启用了审计功能,将安装内置 Elasticsearch。对于生产环境,如果您想启用审计功能,强烈建议在该 YAML 文件中设置以下值,尤其是 externalElasticsearchUrl 和 externalElasticsearchPort。提供以下信息后,KubeSphere 将直接对接外部 Elasticsearch,不再安装内置 Elasticsearch。

    es:  # Storage backend for logging, tracing, events and auditing.
      elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
      elasticsearchDataReplicas: 1     # The total number of data nodes.
      elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
      elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
      logMaxAge: 7                     # Log retention day in built-in Elasticsearch. It is 7 days by default.
      elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
      externalElasticsearchUrl: # The URL of external Elasticsearch.
      externalElasticsearchPort: # The port of external Elasticsearch.
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:验证您可以使用右下角工具箱中的操作审计功能。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n kubesphere-logging-system
    

    如果组件运行成功,输出结果如下:

    NAME                                                              READY   STATUS      RESTARTS   AGE
    elasticsearch-logging-curator-elasticsearch-curator-159872n9g9g   0/1     Completed   0          2d10h
    elasticsearch-logging-curator-elasticsearch-curator-159880tzb7x   0/1     Completed   0          34h
    elasticsearch-logging-curator-elasticsearch-curator-1598898q8w7   0/1     Completed   0          10h
    elasticsearch-logging-data-0                                      1/1     Running     1          2d20h
    elasticsearch-logging-data-1                                      1/1     Running     1          2d20h
    elasticsearch-logging-discovery-0                                 1/1     Running     1          2d20h
    fluent-bit-6v5fs                                                  1/1     Running     1          2d20h
    fluentbit-operator-5bf7687b88-44mhq                               1/1     Running     1          2d20h
    kube-auditing-operator-7574bd6f96-p4jvv                           1/1     Running     1          2d20h
    kube-auditing-webhook-deploy-6dfb46bb6c-hkhmx                     1/1     Running     1          2d20h
    kube-auditing-webhook-deploy-6dfb46bb6c-jp77q                     1/1     Running     1          2d20h
    

    KubeSphere 服务网格

    KubeSphere 服务网格基于 Istio,将微服务治理和流量管理可视化。它拥有强大的工具包,包括熔断机制、蓝绿部署、金丝雀发布、流量镜像、分布式链路追踪、可观测性和流量控制等。KubeSphere 服务网格支持代码无侵入的微服务治理,帮助开发者快速上手,Istio 的学习曲线也极大降低。KubeSphere 服务网格的所有功能都旨在满足用户的业务需求。

    KubeSphere v3.1.1 使用的 istio 版本为 v1.6.10

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    servicemesh:
      enabled: true # 将“false”更改为“true”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 servicemesh,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    servicemesh:
      enabled: true # 将“false”更改为“true”。
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:进入服务组件,查看 Istio 的状态。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n istio-system
    

    如果组件运行成功,输出结果可能如下:

    NAME                                    READY   STATUS    RESTARTS   AGE
    istio-ingressgateway-78dbc5fbfd-f4cwt   1/1     Running   0          9m5s
    istiod-1-6-10-7db56f875b-mbj5p          1/1     Running   0          10m
    jaeger-collector-76bf54b467-k8blr       1/1     Running   0          6m48s
    jaeger-operator-7559f9d455-89hqm        1/1     Running   0          7m
    jaeger-query-b478c5655-4lzrn            2/2     Running   0          6m48s
    kiali-f9f7d6f9f-gfsfl                   1/1     Running   0          4m1s
    kiali-operator-7d5dc9d766-qpkb6         1/1     Running   0          6m53s
    

    网络策略

    从 3.0.0 版本开始,用户可以在 KubeSphere 中配置原生 Kubernetes 的网络策略。网络策略是一种以应用为中心的结构,能够指定如何允许 Pod 通过网络与各种网络实体进行通信。通过网络策略,用户可以在同一集群内实现网络隔离,这意味着可以在某些实例 (Pod) 之间设置防火墙。

    • 在启用之前,请确保集群使用的 CNI 网络插件支持网络策略。支持网络策略的 CNI 网络插件有很多,包括 Calico、Cilium、Kube-router、Romana 和 Weave Net 等。
    • 建议您在启用网络策略之前,使用 Calico 作为 CNI 插件。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    network:
      networkpolicy:
        enabled: true # 将“false”更改为“true”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 network.networkpolicy,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    network:
      networkpolicy:
        enabled: true # 将“false”更改为“true”。
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    如果能在网络管理中看到网络策略,说明安装成功,因为安装组件之后才会显示这部分。

    Metrics Server

    KubeSphere 支持用于部署的 Pod 弹性伸缩程序 (HPA)。在 KubeSphere 中,Metrics Server 控制着 HPA 是否启用。您可以根据不同类型的指标(例如 CPU 和内存使用率,以及最小和最大副本数),使用 HPA 对象对部署 (Deployment) 自动伸缩。通过这种方式,HPA 可以帮助确保您的应用程序在不同情况下都能平稳、一致地运行。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    metrics_server:
      enabled: true # 将“false”更改为“true”。
    

    如果在某些云托管的 Kubernetes 引擎上安装 KubeSphere,那么很可能环境中已经安装了 Metrics Server。在这种情况下,不建议在 cluster-configuration.yaml 中启用 Metrics Server,因为这可能会在安装过程中引起冲突。

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该 YAML 文件中,搜寻到 metrics_server,将 enabled 的 false 改为 true。完成后,点击右下角的更新,保存配置。
    metrics_server:
      enabled: true # 将“false”更改为“true”。
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    执行以下命令以验证 Metrics Server 的 Pod 在正常运行。

    kubectl get pod -n kube-system
    

    如果 Metrics Server 安装成功,那么集群可能会返回以下输出(不包括无关 Pod):

    NAME                                        READY   STATUS    RESTARTS   AGE
    metrics-server-6c767c9f94-hfsb7             1/1     Running   0          9m38s
    

    服务拓扑图

    可以启用服务拓扑图以集成 Weave Scope(Docker 和 Kubernetes 的可视化和监控工具)。Weave Scope 使用既定的 API 收集信息,为应用和容器构建拓扑图。服务拓扑图显示在您的项目中,将服务之间的连接关系可视化。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    network:
      topology:
        type: weave-scope # 将“none”更改为“weave-scope”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该配置文件中,搜寻到 network,将 network.topology.type 更改为 weave-scope。完成后,点击右下角的更新保存配置。
    network:
      topology:
        type: weave-scope # 将“none”更改为“weave-scope”。
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:进入一个项目中,导航到应用负载下的服务,即可看到拓扑图选项卡下服务的拓扑图。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n weave
    

    如果组件运行成功,输出结果可能如下:

    NAME                                        READY   STATUS    RESTARTS   AGE
    weave-scope-agent-48cjp                     1/1     Running   0          3m1s
    weave-scope-agent-9jb4g                     1/1     Running   0          3m1s
    weave-scope-agent-ql5cf                     1/1     Running   0          3m1s
    weave-scope-app-5b76897b6f-8bsls            1/1     Running   0          3m1s
    weave-scope-cluster-agent-8d9b8c464-5zlpp   1/1     Running   0          3m1s
    

    容器组 IP 池

    容器组 IP 池用于规划 Pod 网络地址空间,每个容器组 IP 池之间的地址空间不能重叠。创建工作负载时,可选择特定的容器组 IP 池,这样创建出的 Pod 将从该容器组 IP 池中分配 IP。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    network:
      ippool:
        type: calico # 将“none”更改为“calico”。
    

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该配置文件中,搜寻到 network,将 network.ippool.type 更改为 calico。完成后,点击右下角的更新保存配置。
    network:
      ippool:
        type: calico # 将“none”更改为“calico”。
    
    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    在集群管理页面,可以在网络管理下看到容器组 IP 池。

    KubeEdge

    KubeEdge 是一个开源系统,用于将容器化应用程序编排功能扩展到边缘的主机。KubeEdge 支持多个边缘协议,旨在对部署于云端和边端的应用程序与资源等进行统一管理。

    KubeEdge 的组件在两个单独的位置运行——云上和边缘节点上。在云上运行的组件统称为 CloudCore,包括 Controller 和 Cloud Hub。Cloud Hub 作为接收边缘节点发送请求的网关,Controller 则作为编排器。在边缘节点上运行的组件统称为 EdgeCore,包括 EdgeHub,EdgeMesh,MetadataManager 和 DeviceTwin。有关更多信息,请参见 KubeEdge 网站。

    启用 KubeEdge 后,可以为集群添加边缘节点并在这些节点上部署工作负载。

    安装 KubeSphere 前

    修改 cluster-configuration.yaml 文件中开启

    kubeedge:
      enabled: true # 将“false”更改为“true”。
    

    将 kubeedge.cloudCore.cloudHub.advertiseAddress 的值设置为集群的公共 IP 地址或边缘节点可以访问的 IP 地址。

    安装 KubeSphere 后

    1. 以 admin 身份登录控制台,点击左上角的平台管理,选择集群管理。
    2. 点击自定义资源 CRD,在搜索栏中输入 clusterconfiguration,点击搜索结果查看其详细页面。
    3. 在资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件。
    4. 在该配置文件中,搜寻到 kubeedge.enabled,将 false 更改为 true 以启用 KubeEdge。
    kubeedge:
      enabled: true # 将“false”更改为“true”。
    
    1. 将 kubeedge.cloudCore.cloudHub.advertiseAddress 的值设置为集群的公共 IP 地址或边缘节点可以访问的 IP 地址。完成后,点击右下角的更新保存配置。

    如果集群是从 KubeSphere v3.0.0 升级而来,cluster-configuration.yaml 中不会包含 KubeEdge 的配置。有关更多信息,请参见如何在升级后启用 KubeEdge

    1. 可以执行以下命令,使用 Web Kubectl 工具来检查安装过程:
    kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
    

    验证

    方法一:在集群管理页面,您可以看到节点管理下出现边缘节点板块。

    方法二:

    执行以下命令来检查 Pod 的状态:

    kubectl get pod -n kubeedge
    

    如果组件运行成功,输出结果可能如下:

    NAME                                              READY   STATUS    RESTARTS   AGE
    cloudcore-5f994c9dfd-r4gpq                        1/1     Running   0          5h13m
    edge-watcher-controller-manager-bdfb8bdb5-xqfbk   2/2     Running   0          5h13m
    iptables-hphgf                                    1/1     Running   0          5h13m
    

    如果您在启用 KubeEdge 时未设置 kubeedge.cloudCore.cloudHub.advertiseAddress,则 CloudCore 无法正常运行 (CrashLoopBackOff)。在这种情况下,请运行 kubectl -n kubeedge edit cm cloudcore 添加集群的公共 IP 地址或边缘节点可以访问的 IP 地址。

  • 相关阅读:
    兼容火狐回车事件
    html的锚链接位置偏差解决
    jq记住密码
    PHP界面显示中文乱码
    ThinkPHP5.0学习1
    Fatal error: Call to undefined function pasterTempletDiy()
    dede问答模块修改
    PHP:Deprecated: Function set_magic_quotes_runtime() is deprecated 错误
    jq根据文本显示内容设置样式
    Tomcat Remote Debug操作和原理
  • 原文地址:https://www.cnblogs.com/leffss/p/15162675.html
Copyright © 2011-2022 走看看