2023-04-12 10:12:17 +08:00
|
|
|
|
[#]: subject: "How to Install Kubernetes (k8s) Metrics Server Step by Step"
|
2023-04-03 08:42:34 +08:00
|
|
|
|
[#]: via: "https://www.linuxtechi.com/how-to-install-kubernetes-metrics-server/"
|
|
|
|
|
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
|
|
|
|
[#]: collector: "lkxed"
|
|
|
|
|
[#]: translator: "geekpi"
|
2023-04-12 10:12:17 +08:00
|
|
|
|
[#]: reviewer: "wxy"
|
|
|
|
|
[#]: publisher: "wxy"
|
|
|
|
|
[#]: url: "https://linux.cn/article-15714-1.html"
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
如何逐步安装 Kubernetes(k8s)指标服务器
|
2023-04-03 08:42:34 +08:00
|
|
|
|
======
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
![][0]
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
> 在这篇文章中,我们将逐步介绍如何安装 Kubernetes 指标服务器。
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
Kubernetes(k8s)指标服务器是一个组件,用于收集和聚合来自 Kubernetes 集群中各种来源(包括节点和 <ruby>容器荚<rt>Pod</rt></ruby>)的指标数据。此数据可用于监控和优化资源利用率、识别潜在问题并提高 Kubernetes 集群的整体性能。
|
|
|
|
|
|
|
|
|
|
指标服务器收集资源利用率数据,例如集群中节点和容器荚的 CPU 和内存使用情况。它提供了一个 API 端点,可用于查询此数据并检索集群中特定资源的指标。
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
##### 先决条件
|
|
|
|
|
|
|
|
|
|
- 启动并运行 Kubernetes 集群(v1.21 或更高版本)。
|
2023-04-12 10:12:17 +08:00
|
|
|
|
- `kubectl` 命令行工具已安装,并配置为与你的 Kubernetes 集群交互。
|
2023-04-03 08:42:34 +08:00
|
|
|
|
- 创建和修改 Kubernetes 对象的能力。
|
|
|
|
|
|
|
|
|
|
事不宜迟,让我们深入了解安装步骤。
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
### 步骤 1 下载指标服务器清单
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
第一步是从 Kubernetes GitHub 仓库下载最新的指标服务器清单文件。使用下面的 `curl` 命令下载 yaml 文件:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# curl -LO https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][1]
|
|
|
|
|
|
|
|
|
|
如果你计划在高可用性模式下安装指标服务器,请下载以下清单文件:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# curl https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability-1.21+.yaml
|
|
|
|
|
```
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
### 步骤 2 修改指标服务器 Yaml 文件
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
接下来,你需要修改指标服务器的 yaml 文件以设置一些配置选项:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# vi components.yaml
|
|
|
|
|
```
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
找到 `container` 下的 `args` 部分,添加以下行:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
- --kubelet-insecure-tls
|
|
|
|
|
```
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
在 `spec` 下,添加以下参数:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
hostNetwork: true
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][2]
|
|
|
|
|
|
|
|
|
|
保存并关闭文件。
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
### 步骤 3 部署指标服务器
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
现在,我们准备好部署指标服务器,运行以下 `kubectl` 命令:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# kubectl apply -f components.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][3]
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
### 步骤 4 验证指标服务器部署
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
部署指标服务器后,通过检查在 `kube-system` 命名空间中运行的容器荚状态来验证它的状态:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# kubectl get pods -n kube-system
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][4]
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
上面的输出确认指标服务器容器荚已启动并正在运行。
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
### 步骤 5 测试指标服务器安装
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
最后,你可以通过运行以下 `kubectl` 命令来测试指标服务器:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# kubectl top nodes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
此命令应显示集群中每个节点的资源利用率,包括 CPU 和内存使用率。
|
|
|
|
|
|
|
|
|
|
![][5]
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
要查看当前命名空间或特定命名空间的容器荚资源利用率,请运行:
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# kubectl top pod
|
|
|
|
|
# kubectl top pod -n kube-system
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][6]
|
|
|
|
|
|
|
|
|
|
这就是这篇文章的全部内容,我希望你能从中找到有用的信息。请在下面的评论部分发表你的反馈和疑问。
|
|
|
|
|
|
2023-04-12 10:12:17 +08:00
|
|
|
|
*(题图:MJ: Kubernetes container paper art light blue background ultra-detailed topview)*
|
|
|
|
|
|
2023-04-03 08:42:34 +08:00
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.linuxtechi.com/how-to-install-kubernetes-metrics-server/
|
|
|
|
|
|
|
|
|
|
作者:[Pradeep Kumar][a]
|
|
|
|
|
选题:[lkxed][b]
|
2023-04-03 08:44:53 +08:00
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2023-04-12 10:12:17 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2023-04-03 08:42:34 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: https://www.linuxtechi.com/author/pradeep/
|
|
|
|
|
[b]: https://github.com/lkxed/
|
|
|
|
|
[1]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Download-Metrics-Server-Yaml-file-Curl-Command-1024x127.png?ezimgfmt=ng:webp/ngcb22
|
|
|
|
|
[2]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Edit-Metrics-Server-Yaml-file.png
|
|
|
|
|
[3]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Deploy-Metrics-Server-Kubectl-Command.png
|
|
|
|
|
[4]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Metrics-Server-Pods-Status-Kube-System.png
|
|
|
|
|
[5]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Kubectl-top-node-command-Output.png?ezimgfmt=ng:webp/ngcb22
|
2023-04-12 10:12:17 +08:00
|
|
|
|
[6]: https://www.linuxtechi.com/wp-content/uploads/2023/03/Kubectl-top-pod-command-output.png
|
|
|
|
|
[0]: https://img.linux.net.cn/data/attachment/album/202304/12/100919k6p6yyweu6nv6nkh.jpg
|