website/content/zh/docs/pluggable-components/metrics-server.md
serenashe 53fa90dfe9 Update enable pluggable components docs.
Signed-off-by: serenashe <serenashe@yunify.com>
2021-11-01 11:21:56 +08:00

5.1 KiB
Raw Blame History

title keywords description linkTitle weight
Metrics Server Kubernetes, KubeSphere, Metrics Server 了解如何启用 Metrics Server 以使用 HPA 对部署进行自动伸缩。 Metrics Server 6910

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

在安装前启用 Metrics Server

在 Linux 上安装

当您在 Linux 上安装多节点 KubeSphere 时,首先需要创建一个配置文件,该文件列出了所有 KubeSphere 组件。

  1. 基于在 Linux 上安装 KubeSphere 的教程,您需要创建一个默认文件 config-sample.yaml,通过执行以下命令修改该文件:

    vi config-sample.yaml
    

    {{< notice note >}} 如果您采用 All-in-One 安装,则不需要创建 config-sample.yaml 文件因为可以直接创建集群。一般来说All-in-One 模式是为那些刚接触 KubeSphere 并希望熟悉系统的用户而准备的。如果您想在这个模式下启用 Metrics Server比如用于测试请参考下面的部分,查看如何在安装后启用 Metrics Server。 {{</ notice >}}

  2. 在该文件中,搜寻到 metrics_server,并将 enabledfalse 改为 true,完成后保存文件。

    metrics_server:
      enabled: true # 将“false”更改为“true”。
    
  3. 使用该配置文件创建集群:

    ./kk create cluster -f config-sample.yaml
    

在 Kubernetes 上安装

在 Kubernetes 上安装 KubeSphere 教程中演示了在 Kubernetes 上安装 KubeSphere 的流程。若想安装可选组件 Metrics Server您可以先在 cluster-configuration.yaml 文件中先启用该组件。

  1. 下载文件 cluster-configuration.yaml,并打开文件进行编辑。

    vi cluster-configuration.yaml
    
  2. 在本地文件 cluster-configuration.yaml 中,导航到 metrics_server,并在 enabled 一行将 false 更改为 true。完成之后,请保存文件。

    metrics_server:
      enabled: true # 将“false”更改为“true”。
    
  3. 执行以下命令以开始安装:

    kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
    
    kubectl apply -f cluster-configuration.yaml
    

    {{< notice note >}}

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

在安装后启用 Metrics Server

  1. admin 身份登录控制台。点击左上角平台管理,选择集群管理

  2. 点击 CRD,在搜索栏中输入 clusterconfiguration。点击搜索结果查看详情页。

    {{< notice info >}}

定制资源定义CRD能让用户创建新的资源类型而无需添加其他 API 服务器。用户可以像其他原生 Kubernetes 对象一样使用这些资源。

{{</ notice >}}
  1. 资源列表中,点击 ks-installer 右侧的 ,选择编辑配置文件

  2. 在该 YAML 文件中,导航到 metrics_server,在 enabled 一行将 false 更改为 true。完成后,点击右下角的更新以保存配置。

    metrics_server:
      enabled: true # 将“false”更改为“true”。
    
  3. 您可以通过执行以下命令,使用 kubectl 来检查安装过程:

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

    {{< notice note >}}

可以通过点击控制台右下角的 找到 kubectl 工具。 {{</ notice >}}

验证组件的安装

执行以下命令以验证 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