2017-04-22 1 views
0

저는 kubernetes를 처음 사용하고 GCE로 실행되는 redis와 mongodb로 테스트 할 수있는 응용 프로그램을 가지고 있습니다. 로그 파일을 fluentd로 가져 와서 logz에 보내고 싶습니다.Kubernetes에서 fluentd로 컨테이너 로그를 읽을 때 허가 문제가 발생했습니다.

다음의 유동적 인 구성 파일을 사용합니다. 내 로컬 컴퓨터에서 유사한 버전을 테스트했습니다.

<source> 
    @type tail 
    path /var/log/containers/squidex*.log 
    pos_file /var/log/squidex.log.pos 
    tag squidex.logs 
    format json 
</source> 

<match squidex.logs> 
    @type copy 
    <store> 
     @type logzio_buffered 
     endpoint_url https://listener.logz.io:8071?token=... 
     output_include_time true 
     output_include_tags true 
     buffer_type file 
     buffer_path /fluentd/log/squidex.log.buffer 
     flush_interval 10s 
     buffer_chunk_limit 1m 
    </store> 
    <store> 
     @type stdout 
    </store> 
</match> 

내는 Kubernetes 구성은 다음과 같습니다

2017-04-22T09:49:22.286740784Z 2017-04-22 09:49:22 +0000 [warn]: 
/var/log/containers/squidex-282724611-3nhtw_default_squidex-ed7c437e677d3438c137cdc80110d106339999a6ba8e495a5752fe6d5da9e70d.log unreadable. 
It is excluded and would be examined next time 

:

--- 
apiVersion: extensions/v1beta1 
kind: DaemonSet 
metadata: 
    name: fluentd-logging 
    labels: 
    app: fluentd-logging 
spec: 
    template: 
    metadata: 
     labels: 
     app: fluentd-logging 
    spec: 
     containers: 
     - name: fluentd 
     image: gcr.io/squidex-157415/squidex-fluentd:latest 
     resources: 
      limits: 
      memory: 200Mi 
      requests: 
      cpu: 40m 
     volumeMounts: 
     - name: varlog 
      mountPath: /var/log 
     terminationGracePeriodSeconds: 30 
     volumes: 
     - name: varlog 
     hostPath: 
      path: /var/log 

거의 모든 작품,하지만 난이 포드에서 로그 출력에서 ​​다음 항목을 참조하십시오 Fluentd에 포드를 실행할 때 해당 로그 파일에 대한 사용 권한을 얻으려면 어떻게합니까?

+0

나는 당신이 문제는/var/log/containers는 실제로 로그 파일을 보관하지 않지만 그것들에 링크한다는 것이다. 컨테이너를 소유 한 FS와 연결되어야합니다. 그래서 아마 둘 다 마운트해야합니다. –

답변

1

이것은 사용 권한 문제는 아니지만 symlinks가 깨졌습니다. Kubernetes는 /var/log/containers ~ /var/log/pods ~ /var/lib/docker/containers의 심볼릭 링크를 사용하고 있습니다. 당신은 같은 것을 포함해야한다 ls -la

귀하의 DaemonSet 구성을 사용하여 클러스터의 모든 노드에서이를 확인할 수 있습니다

volumeMounts: 
- name: varlog 
    mountPath: /var/log/ 
    readOnly: true 
    - name: varlibdockercontainers 
    mountPath: /var/lib/docker/containers 
    readOnly: true 
[...] 
volumes: 
- name: varlog 
    hostPath: 
    path: /var/log/ 
- name: varlibdockercontainers 
    hostPath: 
    path: /var/lib/docker/containers 

이렇게하면 마운트 모두 로그는 디렉토리를 파일과 심볼릭 링크의 심볼릭 링크 귀하의 Fluentd에 너무 모든 것을 읽을 수 있습니다.