如何将所有Pod的日志存储在Node上一处的kubernetes中? [英] How to store logs of all pods in kubernetes at one place on Node?

查看:725
本文介绍了如何将所有Pod的日志存储在Node上一处的kubernetes中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Pod的日志存储在kubernetes中的一个地方.即 kubectl日志podname

I want to store logs of pods in kubernetes at one place. i.e output of kubectl logs podname

我提到了这个问题 Kubernetes基本pod记录,这使我成功记录了计数器.如何在规范中修改此args属性,以获取存储在文件中的 kubectl日志podname 的输出?

I referred this question Kubernetes basic pod logging which gives me successfully logs for counter...How to modify this args attribute in spec to get output of kubectl logs podname stored in file at one place?

这是我创建的pod.yaml,但无法在/tmp/logs/

Here is my pod.yaml i created but not able to see any file at location /tmp/logs/

apiVersion: v1
kind: Service
metadata:
  name: spring-boot-demo-pricing
spec:
  ports:
  - name: spring-boot-pricing
    port: 8084
    targetPort: 8084
  selector:
    app: spring-boot-demo-pricing

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: spring-boot-demo-pricing
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: spring-boot-demo-pricing
    spec:
      containers:
      - name: spring-boot-demo-pricing
        image: djtijare/a2ipricing12062019:v1
        imagePullPolicy: IfNotPresent
       # envFrom:
        #- configMapRef:
        #    name: spring-boot-demo-config-map
        resources:
          requests:
            cpu: 100m
            memory: 1Gi
        ports:
        - containerPort: 8084
        args: [/bin/sh, -c,
          'i=0; while true; do echo "$i: $(date)" >> /u01/kubernetes_prac/logs/log_output.txt; i=$((i+1)); sleep 1; done']
        volumeMounts:
        - name: varlog
          mountPath: /u01/kubernetes_prac/logs
      volumes:
       - name: varlog
         hostPath:
           path: /tmp/logs

推荐答案

正确的方法是将日志存储在集群外部,例如,如果您使用AWS,则有将日志存储到cloudwatch,s3等规定.一个例子可能是 fluentd ,它写了许多资料. Kubernetes集群在VPC(虚拟私有云)上运行并提供对集群中节点的访问的原因可能并非始终都是正确的.因此,这是一种遵循的方法.

The right approach would be to store logs outside the cluster, say for example if you use AWS, there are provisions like storing logs to cloudwatch, s3, etc. An example might be fluentd, that writes to many sources. The reason being that kubernetes clusters run on VPC(Virtual private cloud) and providing access to the nodes in the cluster might not be right all the time. So this is one such approach followed.

链接提供了将所有容器的日志公开给EFK的准则(Elasticsearch,Fluentd和Kibana).

This link provides the guideline to expose all the containers' log to EFK(Elasticsearch, Fluentd, and Kibana).

这篇关于如何将所有Pod的日志存储在Node上一处的kubernetes中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆