如何为 Kubernetes 监控设置 TOBS(可观察性栈

金钱(警告)

** 状态:** 被贬值

此文章已被删除,不再保留。

理由

TOBS安装器已被上流贬值。

相反,看

官方 TOBS 文件 )。

美元

介绍

TOBS,简称The Observability Stack,是一个预先包装的监控工具和仪表板接口的分布,可以安装到任何现有的Kubernetes集群中。它包括许多最流行的开源观测工具,Prometheus和Grafana作为基线,包括Promlens,TimescaleDB,Alertmanager等。

TOBS 使用标准的 Kubernetes Helm 图表来配置和更新部署,可以安装到任何 Kubernetes 集群中,但如果您运行kubectl来管理您的集群,而不是远程节点,则可以更有效地进行示范。

在本教程中,您将安装TOBS到现有的Kubernetes集群中,并学习如何更新,配置和浏览其组件仪表板。

前提条件

要遵循本教程,您将需要:

此设置将使用 DigitalOcean Kubernetes集群,但您可以自由地使用 另一种方法创建集群。您的 Kubernetes 版本应与 支持的 TOBS 版本匹配。

  • 在本地计算机上安装的kubectl命令行工具,并配置以连接到您的集群。您可以阅读有关安装kubectl的更多信息(在官方文档中)。

步骤 1 – 验证您的 Kubernetes 配置

要安装 TOBS,你首先应该有一个有效的 Kubernetes 配置设置与kubectl,从那里你可以 ping 你的工人节点. 你可以测试通过运行kubectl 得到节点:

1kubectl get nodes

如果kubectl能够连接到您的Kubernetes集群,并且按预期运行,此命令将返回具有准备状态的节点列表:

1[secondary_label Output]
2NAME STATUS ROLES AGE VERSION
3pool-uqv8a47h0-ul5a7 Ready    <none>   22m v1.21.5
4pool-uqv8a47h0-ul5am Ready    <none>   21m v1.21.5
5pool-uqv8a47h0-ul5aq Ready    <none>   21m v1.21.5

如果成功,您可以转到 步骤 2

默认情况下,kubectl会搜索一个文件在~/.kube/config以了解你的环境. 为了验证这个文件存在并包含有效的YAML语法,你可以运行在其上,以查看其前几个行,i:

1head ~/.kube/config
1[secondary_label Output]
2apiVersion: v1
3clusters:
4- cluster:
5    certificate-authority-data:
6

如果文件不存在,请确保您是与您配置 Kubernetes 相同的用户登录。 ~/ 路径反映了个别用户的首页目录,而 Kubernetes 配置是默认为每个用户保存的。

如果您正在使用 DigitalOcean 的 Managed Kubernetes,请确保在设置一个群集后运行doctl kubernetes 群集 kubeconfig save命令,以便您的本地机器可以对其进行身份验证。

1doctl kubernetes cluster kubeconfig save your-cluster-name

如果您正在使用此机器访问多个集群,您应该查看 Kubernetes 文档关于使用环境变量和多个配置文件,以避免冲突。

步骤 2 — 安装TOBS并测试您的终端

TOBS包括以下组件:

  • [Prometheus] (https://prometheus.io/)是一个时间序列数据库和监测工具,它通过投票测量终点来工作,并删除和处理这些终点所暴露出的数据. 它允许您使用promQL,一个时间序列数据查询语言查询此数据. (_)
  • [Alertmanager] (https://prometheus.io/docs/alerting/latest/alertmanager/]),通常部署在普罗米修斯一并,形成堆栈的提示层,处理由普罗米修斯生成的提醒并解析,分组,并引导到电子邮件或[PagerDuty]等集成(https://www.pagerduty.com/). 为了了解更多关于提醒管理器的信息,请查阅[Prometheus documents on attelling (https://prometheus.io/docs/practices/alerting/). (- ]* [Grafana] (LINK5))是一个数据可视化和分析工具,它允许您为自己的度量数据构建仪表板和图表. (- )* [kube-state-meters] (https://github.com/kubernetes/kube-state-metrics)是一个附加代理,它可以听从Kubernetes API服务器,并生成关于部署和Pods等Kubernetes天体状态的度量. 这些度量衡在HTTP端点上作为平正文字使用并被普罗米修斯所消耗. (_ ( )* 最后是节点-出口机,是Prometheus的出口国,运行在集群节点上,向Prometheus提供OS和硬件度量衡,如CPU和内存用量. 这些度量衡还用作HTTP端点上的平话并被普罗米修斯所消耗. ( (英语)

为了安装 TOBS,您首先需要在您的控制板上运行 TOBS 安装程序. 这将设置tobs命令和配置目录.正如前提中提到的,tobs命令仅用于 Linux/macOS/BSD 系统(如官方的 Kubernetes 二进制),所以如果您一直在使用 Windows 到目前为止,您应该在 Windows 子系统 for Linux环境中工作。

查找并运行 TOBS 安装程序:

1curl --proto '=https' --tlsv1.2 -sSLf https://tsdb.co/install-tobs-sh |sh
1[secondary_label Output]
2tobs 0.7.0 was successfully installed 🎉
3
4Binary is available at /root/.local/bin/tobs.

您现在可以将TOBS推到您的Kubernetes集群中,这是通过使用您新提供的tobs命令的单行器完成的:

1tobs install

取决于您确切的 Kubernetes 版本,输出中可能有多个警告,但只要您最终收到欢迎到管道消息,您可以忽略这些:

 1[secondary_label Output]
 2WARNING: Using a generated self-signed certificate for TLS access to TimescaleDB.
 3         This should only be used for development and demonstration purposes.
 4         To use a signed certificate, use the "--tls-timescaledb-cert" and "--tls-timescaledb-key"
 5         flags when issuing the tobs install command.
 6
 7Creating TimescaleDB tobs-certificate secret
 8Creating TimescaleDB tobs-credentials secret
 9skipping to create TimescaleDB s3 backup secret as backup option is disabled.
102022/01/10 11:25:34 Transport: unhandled response frame type *http.http2UnknownFrame
112022/01/10 11:25:35 Transport: unhandled response frame type *http.http2UnknownFrame
122022/01/10 11:25:35 Transport: unhandled response frame type *http.http2UnknownFrame
13Installing The Observability Stack
142022/01/10 11:25:37 Transport: unhandled response frame type *http.http2UnknownFrame
15W0110 11:25:55.438728 75479 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
16W0110 11:25:55.646392 75479 warnings.go:70] policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
1718👋🏽 Welcome to tobs, The Observability Stack for Kubernetes
19

从现在开始,输出将包含连接到您的浏览器中的每个 Prometheus、TimescaleDB、PromLens 和Grafana Web 端点的说明。

 1[secondary_label Output]
 2###############################################################################
 3🔥 PROMETHEUS NOTES:
 4###############################################################################
 5
 6Prometheus can be accessed via port 9090 on the following DNS name from within your cluster:
 7tobs-kube-prometheus-prometheus.default.svc.cluster.local
 8
 9Get the Prometheus server URL by running these commands in the same shell:
10  tobs prometheus port-forward
11
12The Prometheus alertmanager can be accessed via port 9093 on the following DNS name from within your cluster:
13tobs-kube-prometheus-alertmanager.default.svc.cluster.local
14
15Get the Alertmanager URL by running these commands in the same shell:
16  export POD_NAME=$(kubectl get pods --namespace default -l "app=alertmanager,alertmanager=tobs-kube-prometheus-alertmanager" -o jsonpath="{.items[0].metadata.name}")
17  kubectl --namespace default port-forward $POD_NAME 9093
18WARNING! Persistence is disabled on AlertManager.
19         You will lose your data when the AlertManager pod is terminated.
20
21###############################################################################
22🐯 TIMESCALEDB NOTES:
23###############################################################################
24
25TimescaleDB can be accessed via port 5432 on the following DNS name from within your cluster:
26tobs.default.svc.cluster.local
27
28To get your password for superuser run:
29    tobs timescaledb get-password -U <user>
30
31To connect to your database, chose one of these options:
32
331. Run a postgres pod and connect using the psql cli:
34    tobs timescaledb connect -U <user>
35
362. Directly execute a psql session on the master node
37   tobs timescaledb connect -m
38
39###############################################################################
40🧐 PROMLENS NOTES:
41###############################################################################
42   PromLens is a PromQL query builder, analyzer, and visualizer.
43
44   You can access PromLens via a local browser by executing:
45    tobs promlens port-forward
46
47   Then you can point your browser to http://127.0.0.1:8081/.
48###############################################################################
49📈 GRAFANA NOTES:
50###############################################################################
51
521. The Grafana server can be accessed via port 80 on
53   the following DNS name from within your cluster:
54   tobs-grafana.default.svc.cluster.local
55
56   You can access grafana locally by executing:
57    tobs grafana port-forward
58
59   Then you can point your browser to http://127.0.0.1:8080/.
60
612. The 'admin' user password can be retrieved by:
62    tobs grafana get-password
63
643. You can reset the admin user password with grafana-cli from inside the pod.
65    tobs grafana change-password <password-you-want-to-set>

每个集群都提供一个 DNS 名称,以便可以从您的任何工作节点访问它们,例如 Prometheus 的 tobs-kube-prometheus-alertmanager.default.svc.cluster.local 此外,每个节点都配置了一个端口转发命令,允许您从本地 Web 浏览器访问它们。

在新终端中,运行tobs prometheus port-forward:

1tobs prometheus port-forward

只要端口转发过程是活跃的,这将占据终端,您可以按Ctrl+C来优雅地停止阻止端口转发的过程,例如当您想要停止端口转发时。接下来,在网页浏览器中,转到URL:http://127.0.0.1:9090/`。您应该看到完整的Prometheus界面运行并从您的集群中生成指标:

Prometheus welcome

您可以对 Grafana 做同样的事情,只要在另一个进程中运行的端口转发,则可以访问 http://127.0.0.1:8080/。 首先,您需要使用安装程序输出提供的get-password`命令:

1tobs grafana get-password
1[secondary_label Output]
2your-grafana-password

然后,您可以使用此密码登录到Grafana界面,运行其端口转发命令,并在浏览器中打开http://127.0.0.1:8080/

1tobs grafana port-forward

Grafana welcome

您现在在您的 Kubernetes 集群中运行一个工作 TOBS 堆栈。 您可以参阅各个组件的文档,以了解各自的功能。 在本教程的最后一步中,您将学习如何更新 TOBS 配置本身。

步骤 3 – 编辑 TOBS 配置和升级

TOBS的配置包含了堆栈中的个别应用程序的一些参数,以及TOBS部署本身的一些参数。它被生成并存储为Kubernetes Helm 图表。您可以通过运行tobs 头盔显示值来输出当前的配置。然而,这将输出整个长配置到您的终端,这可能很难读取。您可以代替将输出导向具有.yaml扩展的文件,因为 Helm 图表都是有效的 YAML 语法:

1tobs helm show-values > values.yaml

文件内容将看起来像这样:

 1[label ~/values.yaml]
 22022/01/10 11:56:37 Transport: unhandled response frame type *http.http2UnknownFrame
 3# Values for configuring the deployment of TimescaleDB
 4# The charts README is at:
 5#    https://github.com/timescale/timescaledb-kubernetes/tree/master/charts/timescaledb-single
 6# Check out the various configuration options (administration guide) at:
 7#    https://github.com/timescale/timescaledb-kubernetes/blob/master/charts/timescaledb-single/admin-guide.md
 8cli: false
 9
10# Override the deployment namespace
11namespaceOverride: ""
12

您可以通过阅读 TOBS 文档查看可用的 TOBS 配置的其他参数。

如果您有任何时候修改此文件以更新部署,您可以使用更新的配置重新安装 TOBS. 只需将 -f 选项传输到 tobs install 命令中,以 YAML 文件作为额外的参数:

1tobs install -f values.yaml

最后,您可以使用以下命令升级 TOBS:

1tobs upgrade

这通过采集最新的上游图来实现相当于头盔升级

结论

在本教程中,您学会了如何在现有的Kubernetes群集上部署和配置TOBS,而TOBS尤其有用,因为它消除了对每个应用程序的个别维护配置细节的需要,同时为运行在群集上的应用程序提供标准化监控。

接下来,您可能想了解如何使用 Cert-Manager来处理您的 Kubernetes 集群的 HTTPS 输入。

Published At
Categories with 技术
comments powered by Disqus