

 **帮助改进此页面** 

要帮助改进本用户指南，请选择位于每个页面右侧窗格中的**在 GitHub 上编辑此页面**链接。

# 使用 Helm 部署 Prometheus
<a name="deploy-prometheus"></a>

您可以使用 Helm 将 Prometheus 部署到集群中，而不使用 Amazon Managed Service for Prometheus。如果您已安装有 Helm，则可使用 `helm version` 命令来检查您的版本。Helm 是 Kubernetes 集群的包管理器。有关 Helm 及其安装方法的更多信息，请参阅 [使用 Helm 在 Amazon EKS 上部署应用程序](helm.md)。

在为您的 Amazon EKS 集群配置 Helm 后，您可以使用它来部署 Prometheus，步骤如下。

1. 创建 Prometheus 命名空间。

   ```
   kubectl create namespace prometheus
   ```

1. 添加 `prometheus-community` 图表存储库。

   ```
   helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
   ```

1. 部署 Prometheus。

   ```
   helm upgrade -i prometheus prometheus-community/prometheus \
       --namespace prometheus \
       --set alertmanager.persistence.storageClass="gp2" \
       --set server.persistentVolume.storageClass="gp2"
   ```
**注意**  
如果您在执行此命令时收到错误 `Error: failed to download "stable/prometheus" (hint: running helm repo update may help)`，请运行 `helm repo update prometheus-community`，然后尝试再次运行第 2 步命令。

   如果您收到错误 `Error: rendered manifests contain a resource that already exists`，请运行 `helm uninstall your-release-name -n namespace `，然后尝试再次运行第 3 步命令。

1. 确认 `prometheus` 命名空间中的所有容器组（pod）均处于 `READY` 状态。

   ```
   kubectl get pods -n prometheus
   ```

   示例输出如下。

   ```
   NAME                                             READY   STATUS    RESTARTS   AGE
   prometheus-alertmanager-59b4c8c744-r7bgp         1/2     Running   0          48s
   prometheus-kube-state-metrics-7cfd87cf99-jkz2f   1/1     Running   0          48s
   prometheus-node-exporter-jcjqz                   1/1     Running   0          48s
   prometheus-node-exporter-jxv2h                   1/1     Running   0          48s
   prometheus-node-exporter-vbdks                   1/1     Running   0          48s
   prometheus-pushgateway-76c444b68c-82tnw          1/1     Running   0          48s
   prometheus-server-775957f748-mmht9               1/2     Running   0          48s
   ```

1. 使用 `kubectl` 将 Prometheus 控制台端口转发到本地计算机。

   ```
   kubectl --namespace=prometheus port-forward deploy/prometheus-server 9090
   ```

1. 在 Web 浏览器中打开 `http://localhost:9090` 来查看 Prometheus 控制台。

1. 从 **- insert metric at cursor (- 在光标位置插入指标)** 菜单选择一个指标，然后选择 **Execute (执行)**。选择 **Graph (图表)** 选项卡显示一段时间内的指标。下图显示了一段时间内的 `container_memory_usage_bytes`。  
![\[Prometheus 指标\]](http://docs.amazonaws.cn/eks/latest/userguide/images/prometheus-metric.png)

1. 在顶部导航栏中，选择 **Status (状态)**，然后选择 **Targets (目标)**。  
![\[Prometheus 控制台\]](http://docs.amazonaws.cn/eks/latest/userguide/images/prometheus.png)

   使用服务发现连接到 Prometheus 的所有 Kubernetes 终端节点将显示。