GithubHelp home page GithubHelp logo

aranova / logrotate-container Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mkilchhofer/logrotate-container

0.0 0.0 0.0 7 KB

A logrotate container image for rotating persistent logs of application inside Kubernetes using Alpine Linux

Shell 71.13% Dockerfile 28.87%

logrotate-container's Introduction

Overview

We need a solution for legacy apps running in a kubernetes cluster writing logs to a file without rotating them (in a traditional way).

Example Setup

I assume that a legacy app inside Kubernetes write logs to a PV resp. PVC called app-logs-pv.

Kubernetes Prereqs

The example PVC app-logs-pv has to be present and the legacy app writes its logfile to this. accessMode of this PVC must be RWX (ReadWriteMany) as we want to rotate them from a different Pod (seperate to the application).

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: app-logs-pv
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 500Mi

Cronjob example setup

Define Logrotate Config

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: logrotate-config
data:
  my_logs.conf: |
    /var/log/app/*.log {
        daily
        missingok
        rotate 7
        compress
        delaycompress
        dateformat -%Y%m%d_%H%M%S
        notifempty
        copytruncate
        su
    }
  my_txt_logs.conf: |
    /var/log/app/*.txt {
        daily
        missingok
        rotate 3
        compress
        delaycompress
        dateformat -%Y%m%d_%H%M%S
        notifempty
        copytruncate
        su
    }

Define Cronjob

---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app-logrotate
spec:
  schedule: "*/1 * * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: logrotate
            image: docker.io/kicm/logrotate
            volumeMounts:
            - name: logrotate-conf
              mountPath: /etc/logrotate.d
            - name: app-logs
              mountPath: /var/log/app
          volumes:
          - name: logrotate-conf
            configMap:
              name: logrotate-config
          - name: app-logs
            persistentVolumeClaim:
              claimName: app-logs-pv
          restartPolicy: OnFailure

logrotate-container's People

Contributors

mkilchhofer avatar psanchezg avatar eugene-marchanka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.