简体   繁体   English

我可以在Kubernetes Pod中运行Google Monitoring Agent吗?

[英]Can I run Google Monitoring Agent inside a Kubernetes Pod?

It seems that the Google Monitoring Agent (powered by Stackdriver ) should be installed on each Node (ie each compute instance, ie each machine) of a Kubernetes cluster. 似乎应该在Kubernetes集群的每个节点 (即每个计算实例,即每台机器)上安装Google Monitoring Agent (由Stackdriver提供支持

However the new plugins , like Nginx , Redis , ElasticSearch ..., need those agents to know the IP of these services. 然而,新的插件 ,如NginxRedisElasticSearch ......,需要这些代理知道这些服务的IP。 This means having kube-proxy running and set up which should mean running that Google Monitoring Agent on a Pod. 这意味着运行和设置kube-proxy应该意味着在Pod上运行Google Monitoring Agent

These two conflict: On one side that agent monitors the entire machine, on the other it monitor services running on one or more machines. 这两个冲突:一方面,代理监视整个计算机,另一方面监视一台或多台计算机上运行的服务。

Can these Stackdriver plugins work on a Google Container Engine (GKE) / Kubernetes cluster? 这些Stackdriver插件可以在Google Container Engine (GKE)/ Kubernetes集群上运行吗?

To monitor each machine (memory, CPU, disk...) it's possible to install the agent on each node (ie on each Compute Instance of your GKE cluster). 要监视每台计算机(内存,CPU,磁盘......),可以在每个节点上(即在GKE集群的每个计算实例上)安装代理。 Note that it'll not work with auto-scaling in the sense that re-created nodes won't have the agent installed. 请注意,在重新创建的节点不安装代理的意义上,它不适用于自动缩放。

To monitor services (number of requests/s, client connection...) it's possible to install the agent plugin in another container so that for example Nginx Pod run two containers: 要监视服务(请求的数量,客户端连接......),可以在另一个容器中安装代理插件,以便例如Nginx Pod运行两个容器:

  • Nginx Nginx的
  • Google Monitoring Agent together with the Nginx plugin Google Monitoring Agent与Nginx插件一起使用

Note: Not fully tested yet. 注意:尚未完全测试。

You can install the StackDriver Agent in your Dockerfile. 您可以在Dockerfile中安装StackDriver Agent。

I have been able to get this working for a couchdb container as follows: 我已经能够为couchdb容器工作,如下所示:

FROM klaemo/couchdb

RUN apt-get update
RUN apt-get install curl lsb-release -y
RUN curl -O https://repo.stackdriver.com/stack-install.sh
RUN apt-get install libyajl2 -y

COPY couchdb.conf /opt/stackdriver/collectd/etc/collectd.d/couchdb.conf

CMD bash stack-install.sh --write-gcm && service stackdriver-agent restart && couchdb

I had tried to use a Stackdriver container in a pod to collect stats about Nginx/Uwsgi in the same pod. 我曾尝试在pod中使用Stackdriver容器来收集同一pod中有关Nginx / Uwsgi的统计信息。 I had some findings that may be not so helpful. 我有一些可能不太有帮助的发现。 Just for your reference. 仅供参考。

To create the stackdriver image, you may reference the docker file created by Keto. 要创建堆栈驱动程序映像,您可以引用由Keto创建的docker文件。 https://hub.docker.com/r/keto/stackdriver/~/dockerfile/ https://hub.docker.com/r/keto/stackdriver/~/dockerfile/

FROM centos:centos7

MAINTAINER Mikael Keto

# add stackdriver repository
RUN curl -o /etc/yum.repos.d/stackdriver.repo https://repo.stackdriver.com/stackdriver-el7.repo

# install stackdriver
RUN yum -y install initscripts stackdriver-agent && yum clean all

RUN mkdir -p /var/lock/subsys; exit 0
ADD run.sh /run.sh
RUN chmod 755 /run.sh

CMD ["/run.sh"]

The run.sh is look like below, run.sh如下所示,

#!/usr/bin/env bash

/opt/stackdriver/stack-config --write-gcm --no-start
/etc/init.d/stackdriver-agent start

while true; do
    sleep 60
    agent_pid=$(cat /var/run/stackdriver-agent.pid 2>/dev/null)

    ps -p $agent_pid > /dev/null 2>&1
    if [ $? != 0 ]; then
        echo "Stackdriver agent pid not found!"
        break;
    fi
done

In the GKE/K8S deployment yaml file, 在GKE / K8S部署yaml文件中,

apiVersion: extensions/v1beta1
kind: Deployment
...
      - name: stackdriver-agent
        image: gcr.io/<project_id>/stackdriver-agent:<your_version>
        command: ['/run.sh']

In my test, I found 在我的测试中,我找到了

  • It will report stats based on [node_name] instead of [container_name]. 它将根据[node_name]而不是[container_name]报告统计信息。
  • It will collect many system stats that are meaningful for a node, but since it is in a pod, it's quite pointless. 它将收集许多对节点有意义的系统统计信息,但由于它位于一个pod中,因此它毫无意义。

Well, I hope to find some way to collect both statistics of the pods and nodes that I need, but I didn't find a easy way to do that. 好吧,我希望找到一些方法来收集我需要的pod和节点的统计数据,但我找不到一个简单的方法来做到这一点。 What I did is do that by Google Python API library, but that takes too much time. 我所做的是通过Google Python API库来实现,但这需要花费太多时间。

There is an other way to use Dockerfile. 还有另一种使用Dockerfile的方法。 When creating the docker image, pre-install necessary libraries for the stackdriver-agent installation. 创建docker镜像时,请为stackdriver-agent安装预安装必要的库。

FROM mongo
RUN apt-get update && apt-get install -y curl lsb-release

# COPY credential
COPY gcloud-credential.json /etc/google/auth/application_default_credentials.json
ENV GOOGLE_APPLICATION_CREDENTIALS "/etc/google/auth/application_default_credentials.json"

# download Stackdriver Agent installer
RUN curl -O https://repo.stackdriver.com/stack-install.sh
RUN chmod +x /stack-install.sh

# COPY stackdriver mongodb plugin
COPY mongodb.conf /opt/stackdriver/collectd/etc/collectd.d/mongodb.conf

Then install the agent using POD lifecycle. 然后使用POD生命周期安装代理。

spec:
  containers:
  - image: your_mongo_image
    name: my-mongo
    ports:
    - containerPort: 27017
    lifecycle:
      postStart:
        exec:
          command: ["/stack-install.sh", "--write-gcm"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 了解 GCP 监控中的 Kubernetes pod 资源利用率 - Understanding Kubernetes pod resource utilization in GCP monitoring 我只能在kubernetes中更改一个Pod吗? - Can i only change one pod in kubernetes? 如何在 kubernetes 容器/pod 中进行日志轮换? - How can I get log rotation working inside a kubernetes container/pod? Terraform 和 GCP:Google kubernetes 集群问题:看不到工作负载(部署、状态集)内部的监控部分(内存和 CPU) - Terraform & GCP: Google kubernetes cluster problem: Can't see monitoring section (memory and cpu) inside workloads (deployments, statefulsets) 如何在kubernetes中使用Google云存储? - How can I use google cloud storage inside kubernetes? 启用堆栈驱动程序监视会导致元数据代理容器崩溃 - Enabling stackdriver monitoring crashes the metadata-agent pod 防火墙背后的Google Stackdriver监控代理 - Google stackdriver monitoring agent behind firewall 使用 Ops Agent 在 Google Cloud 中监控 Apache2 - Monitoring Apache2 in Google Cloud with Ops Agent Hasura on Google Cloud Run - 监控 - Hasura on Google Cloud Run - Monitoring 如何在 Google Cloud Run 中运行 go-cloud-debug-agent,以便我可以在 Stackdriver Debug 中调试我的 go 应用程序 - How to run go-cloud-debug-agent in Google Cloud Run so that I can debug my go app in Stackdriver Debug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM