gpt4 book ai didi

google-compute-engine - 如何从 kubernetes pod 在 Stackdriver 中设置错误报告?

转载 作者:行者123 更新时间:2023-12-02 21:05:16 26 4
gpt4 key购买 nike

我对如何在 kubernetes 中设置错误报告感到有点困惑,因此错误在 Google Cloud Console/Stackdriver“错误报告”中可见?

根据文档 https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine我们需要启用 Fluentd 的“转发输入插件”,然后从我们的应用程序发送异常数据。我认为,如果我们自己设置 Fluentd,这种方法就会起作用,但它已经预先安装在仅运行 gcr.io/google_containers/fluenced-gcp docker 镜像的 pod 中的每个节点上。

我们如何在这些 pod 上启用转发输入并确保节点上的每个 pod 都可以使用 http 端口?当我们向集群添加更多节点时,我们还需要确保默认使用此配置。

任何帮助将不胜感激,也许我从错误的角度看待这一切?

最佳答案

基本思想是启动一个单独的 pod,通过 TCP 接收结构化日志并将其转发到 Cloud Logging,类似于本地运行的 fluidd 代理。请参阅下面我使用的步骤。

(不幸的是,无法使用 Docker 和 Kubernetes 中内置的日志记录支持 - 它只是将 stdout/stderr 中的各个文本行作为单独的日志条目转发,从而阻止错误报告查看完整的堆栈跟踪。)

使用 Dockerfile 为 Fluentd 转发器创建 docker 镜像,如下所示:

FROM gcr.io/google_containers/fluentd-gcp:1.18

COPY fluentd-forwarder.conf /etc/google-fluentd/google-fluentd.conf

其中 Fluentd-forwarder.conf 包含以下内容:

<source>
type forward
port 24224
</source>

<match **>
type google_cloud
buffer_chunk_limit 2M
buffer_queue_limit 24
flush_interval 5s
max_retry_wait 30
disable_retry_limit
</match>

然后构建并推送镜像:

$ docker build -t gcr.io/###your project id###/fluentd-forwarder:v1 .
$ gcloud docker push gcr.io/###your project id###/fluentd-forwarder:v1

您需要一个复制 Controller (fluenced-forwarder-controller.yaml):

apiVersion: v1
kind: ReplicationController
metadata:
name: fluentd-forwarder
spec:
replicas: 1
template:
metadata:
name: fluentd-forwarder
labels:
app: fluentd-forwarder
spec:
containers:
- name: fluentd-forwarder
image: gcr.io/###your project id###/fluentd-forwarder:v1
env:
- name: FLUENTD_ARGS
value: -qq
ports:
- containerPort: 24224

您还需要一个服务 ( Fluentd-forwarder-service.yaml):

apiVersion: v1
kind: Service
metadata:
name: fluentd-forwarder
spec:
selector:
app: fluentd-forwarder
ports:
- protocol: TCP
port: 24224

然后创建复制 Controller 和服务:

$ kubectl create -f fluentd-forwarder-controller.yaml
$ kubectl create -f fluentd-forwarder-service.yaml

最后,在您的应用程序中,不要使用“localhost”和 24224 连接到 fluidd 代理,如 https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine 中所述。 ,使用环境变量 FLUENTD_FORWARDER_SERVICE_HOSTFLUENTD_FORWARDER_SERVICE_PORT 的值。

关于google-compute-engine - 如何从 kubernetes pod 在 Stackdriver 中设置错误报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36379572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com