我将Fluentd用作辅助工具,将nginx日志发送到stdout,以便它们显示在Pod的日志中。我有一个奇怪的问题,即容器启动时Fluentd不会选择配置。
检查Fluentd启动日志后,似乎未加载配置。应该在容器启动时从/etc/fluentd-config/fluentd.conf中加载配置。我已连接到容器,并且配置文件正确,并且PV安装也正确。环境变量也存在。
完整的部署说明如下-如果您想使用它,它是自包含的。
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: PersistentVolume
metadata:
name: weblog-pv
labels:
type: local
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
hostPath:
path: /tmp/weblog
type: DirectoryOrCreate
capacity:
storage: 500Mi
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: weblog-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Mi
- apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-config
data:
fluentd.conf: |
<source>
@type tail
format none
path /var/log/nginx/access.log
tag count.format1
</source>
<match *.**>
@type forward
<server>
name localhost
host 127.0.0.1
</server>
</match>
- apiVersion: v1
kind: Pod
metadata:
name: sidecar-example
labels:
app: webserver
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: logging-vol
mountPath: /var/log/nginx
- name: fdlogger
env:
- name: FLUENTD_ARGS
value: -c /etc/fluentd-config/fluentd.conf
image: fluent/fluentd
volumeMounts:
- name: logging-vol
mountPath: /var/log/nginx
- name: log-config
mountPath: /etc/fluentd-config
volumes:
- name: logging-vol
persistentVolumeClaim:
claimName: weblog-pvc
- name: log-config
configMap:
name: fluentd-config
- apiVersion: v1
kind: Service
metadata:
name: sidecar-svc
spec:
selector:
app: webserver
type: NodePort
ports:
- name: sidecar-port
port: 80
nodePort: 32000
最佳答案
我通过使用stdout而不是重定向到localhost使其工作。
- apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-config
data:
fluent.conf: |
<source>
@type tail
format none
path /var/log/nginx/access.log
tag count.format1
</source>
<match *.**>
@type stdout
</match>
关于kubernetes - Fluentd未从ConfigMap加载配置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56505798/