Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Best Practice Proposal]: Resource output logs should be sent to STDOUT/STDERR #253

Open
taylor opened this issue Feb 28, 2023 · 4 comments
Labels

Comments

@taylor
Copy link
Member

taylor commented Feb 28, 2023

Summary

All K8s resource output / logs should be sent to STDOUT/STDERR as event streams.

Log output, such as normal standard output as well as application errors should be sent to stdout/stderr (standard out, standard error) instead of a log file or directly to a logging system (other than a proxy/sidecar which streams to stdout/stderr).


Services should not concern themselves with routing or storing logs. Instead, events should be streamed, unbuffered, to STDOUT and STDERR for handling by the whatever observability / debugging process is appropriate.

Motivation

The standard output (STDOUT) and standard error (STDERR) can be easily viewed in development. In a production deployment, the CNF streams can be routed to anything, including a central logging service.

Goals

No response

Non-Goals

No response

Proposal

Send all application logs to stdout and all error logs to stderr rather than implementing or using a custom logging solution.
Don't write to a log file, and don't expect log files to be managed. This then requires log rotation and log file maintenance.

Log output being sent to standard out / standard error supports open observability options and a pluggable flexible system.

By sending logs to standard out/standard error "logs will be treated like event streams" as recommended by 12 factor apps principles.

Using a sidecar to collect and stream the output is an option that is appropriate in some circumstances.

Reasons for using stdout:

  • CNFs can end up with many levels and logging across many containers and Pods. stdout / stderr gives a simpler solution for all levels rather than worrying about gathering up each log from all places
  • Containers are ephemeral and any logs on the file system could be lost at any point. Storing logs on the host file system could be a security risk since the host file system may be filled up by accident (or maliciously on purpose). Also log files may not be accessible for gathering in some events and configurations.

Workload Context

No response

User Stories

No response

Notes, Caveats, Constraints

Testing should verify that STDOUT/STDERR is configured for logging. For example, running kubectl get logs returns useful information for diagnosing or troubleshooting issues.

References

@taylor
Copy link
Member Author

taylor commented Feb 28, 2023

@taylor taylor added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 8, 2024
@taylor taylor moved this to Todo in CNTI Best Practices Feb 8, 2024
@taylor
Copy link
Member Author

taylor commented Feb 8, 2024

well-documented best practice. good first issue. draft started

@martin-mat
Copy link
Collaborator

martin-mat commented Feb 13, 2024

I agree with this best practice, however I think this is one aspect of "observability". Perhaps we should consider more aspects of that:

Platform:

  • centralized logging configured for platform and CNFs (fluentd, logstash etc)
  • log rotation configured to prevent uncontrolled log space growth
  • log search/analysis tools set up for easy log handling (elasticsearch etc)
  • provide access to real time logs

CNFs:

  • Log streaming using unbuffered stdout/stderr
  • Setting different log levels (typically Critical, Error, Warning, Info, Debug) best using an environment variable (typically LOG_LEVEL) for easy/unified log level setting inside containers
  • Logging of important lifecycle service states, including startup/available, shutdown
  • Avoid logging of sensitive information (credentials, keys, secrets, personal/company data) - use tagging in logs (****) if needed
  • Format of log information: Use structured logging (json etc) including contextual information - timestamp, hostname, request id etc, for easy log parsing/searching. Use standardized logging formats such as OpenMetrics and OpenTelemetry.

Some additional links
https://www.cncf.io/blog/2023/07/03/kubernetes-logging-best-practices/
https://www.papertrail.com/solution/tips/cloud-native-applications-and-log-management-best-practices/
https://newrelic.com/blog/how-to-relic/log-monitoring-for-cloud-native-architectures
https://www.mezmo.com/blog/what-the-cloud-native-revolution-means-for-log-management

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants