我有一些 kubernetes 应用程序记录到文件而不是 stdout/stderr,我使用 Promtail 边车收集它们。但是由于边车使用“localhost”目标执行,所以我没有一个kubernetes_sd_config
可以为我将 pod 元数据应用于标签的工具。所以我坚持静态地声明我的标签。
# ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: promtail
name: sidecar-promtail
data:
config.yml: |
client:
url: http://loki.loki.svc.cluster.local:3100/loki/api/v1/push
backoff_config:
max_period: 5m
max_retries: 10
min_period: 500ms
batchsize: 1048576
batchwait: 1s
external_labels: {}
timeout: 10s
positions:
filename: /tmp/promtail-positions.yaml
server:
http_listen_port: 3101
target_config:
sync_period: 10s
scrape_configs:
- job_name: sidecar-logs
static_configs:
- targets:
- localhost
labels:
job: sidecar-logs
__path__: "/sidecar-logs/*.log"
----
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-logger
spec:
selector:
matchLabels:
run: test-logger
template:
metadata:
labels:
run: test-logger
spec:
volumes:
- name: nfs
persistentVolumeClaim:
claimName: nfs-claim
- name: promtail-config
configMap:
name: sidecar-promtail
containers:
- name: sidecar-promtail
image: grafana/promtail:2.1.0
volumeMounts:
- name: nfs
mountPath: /sidecar-logs
- mountPath: /etc/promtail
name: promtail-config
- name: simple-logger
image: foo/simple-logger
volumeMounts:
- name: nfs
mountPath: /logs
根据父 pod 的元数据标记收集的日志的最佳方法是什么?