如何将应用程序日志从docker发送到cloudwatch

时间:2017-05-10 15:58:45

标签: docker kubernetes devops amazon-cloudwatch

我们正在使用Kubernetes来部署我们的应用程序泊坞窗映像。

我们希望能够获取应用程序日志并将其推送到cloudwatch。

应用程序日志是使用log4j或log4js生成的,具体取决于微服务的构建语言。

这样做的正确方法是什么?

2 个答案:

答案 0 :(得分:2)

安装Cloudwatch Agent构建容器; to do this you will need a DockerfileAmazon even has docs specifically for this

您需要确保您的基本容器是基于Debian或RHEL的(亚马逊文档似乎只支持代理的这些类型的发行版);例如,基于Debian的系统将安装代理:

curl https://s3.amazonaws.com//aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O

因此,您需要在构建容器时执行上述操作。

安装细节为here

您提到了IAM政策问题; Amazons example policy is below;您需要确保您的容器可以访问。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:DescribeLogStreams"
            ],
            "Resource": [
                "arn:aws:logs:*:*:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::myawsbucket/*"
            ]
        }
    ]
}

GitHub has done this already上有人:

FROM ubuntu:latest
MAINTAINER Ryuta Otaki <otaki.ryuta@classmethod.jp>, Sergey Zhukov <sergey@jetbrains.com>
...
RUN apt-get install -q -y python python-pip wget
RUN cd / ; wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py

我强烈建议你跟随他们;使用Ubuntu并按照文档。不要重新发明轮子。

答案 1 :(得分:0)

此问题听起来与How to Send Kubernetes Logs to AWS CloudWatch?类似。 Kubernetes不支持docker支持的自定义日志驱动程序。您可以使用流利的日志将日志发送到云观察。

相关问题