``本地''将awslog与kubernetes结合使用 [英] Use awslogs with kubernetes 'natively'
问题描述
- 我想出了一种配置k8以使用aws日志而无需任何第三方服务/应用程序的方法.您所要做的就是在master.yaml文件中添加以下行:
spec:
additionalPolicies:
master: |
[
{
"Effect": "Allow",
"Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
"Resource": ["*"]
}
]
node: |
[
{
"Effect": "Allow",
"Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
"Resource": ["*"]
}
]
docker:
logDriver: awslogs
logOpt:
- awslogs-region=eu-west-1
- awslogs-group=<group-name> # make sure that this group already exist (create it manually)
- tag={{.Name}}
-
最后一行是最重要的一行,它将把每个pod的日志流重命名为可读的内容,而不是docker哈希.
The last line is the most important one, and it will rename the log-stream for each pod to something readable instead of the docker hash.
毫无疑问,您必须更新集群才能使更改生效. (请更新集群$ {CLUSTER-NAME}-是)
goes without saying that you have to update the cluster in order for the changes to take affect. (kops update cluster ${CLUSTER-NAME} --yes)
就是这样.打开AWS Cloudwatch并享受您的日志:-)
That's it. Open AWS Cloudwatch and enjoy your logs :-)
话虽如此,我有一个问题.日志流名称包含的信息比我想要的要多得多.知道如何将日志流名称简化为Pod Nice名称吗?
With that said, I have one problem. The log stream name contains much more info than what I would have wanted. Any idea how to trim the log stream name into simply the pod nice name?
我尝试了几种处理'tag'值的方法(例如,tag = {{带split .Name"_"}} {{index.2}} {{end}}),但是它具有更新操作失败.
I have tried several ways of manipulating the 'tag' value (e.g. tag={{ with split .Name "_" }}{{ index . 2 }}{{end}} ), but it has failed the update operation.
日志流名称示例:k8s_POD-NICE-NAME_POD-NICE-NAME-67c77758bf-8knn8_mind_24ed4160-5b5e-11e9-b53a-0a02b6d80d7c_1
logstream name example: k8s_POD-NICE-NAME_POD-NICE-NAME-67c77758bf-8knn8_mind_24ed4160-5b5e-11e9-b53a-0a02b6d80d7c_1
推荐答案
在这种情况下,您将使用Docker awslogs驱动程序进行日志记录.在这种情况下,您必须指定awslogs-stream或tag选项才能将流名称更改为默认值.该标签更具灵活性,我认为它可以解释Go模板标记,因此可以更好地适应您的要求.这样,您可以拥有一个更友好的流名称,而不是容器ID.
In this case you are using the Docker awslogs driver for logging. In which case you have to specify awslogs-stream or tag options to change the stream name from default. The tag is a bit more flexible and I think it will adjust to your requirements better, since it interprets Go template markup. This way you can have a more friendly stream name instead of the container ID.
来自docker文档:
From docker documentation:
指定标记以替代awslogs-stream选项.标签解释Go模板标记,例如{{.ID}},{{.FullID}}或{{.Name}}码头工人.{{.ID}}.有关所有支持的模板替换的详细信息,请参见标签选项文档.
Specify tag as an alternative to the awslogs-stream option. tag interprets Go template markup, such as {{.ID}}, {{.FullID}} or {{.Name}} docker.{{.ID}}. See the tag option documentation for details on all supported template substitutions.
同时指定了awslogs-stream和tag时,为awslogs-stream提供的值将覆盖由tag指定的模板.
When both awslogs-stream and tag are specified, the value supplied for awslogs-stream overrides the template specified with tag.
如果未指定,则将容器ID用作日志流.
If not specified, the container ID is used as the log stream.
在此处查看tag和awslogs-stream选项: https://docs.docker.com/config/containers/logging/awslogs/
See tag and awslogs-stream options here: https://docs.docker.com/config/containers/logging/awslogs/
这篇关于``本地''将awslog与kubernetes结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!