⎈ k8s knowledge compiler

System Logs [page]deterministic

concepts

System component logs record events happening in cluster, which can be very useful for debugging. You can configure log verbosity to see more or less detail. Logs can be as coarse-grained as showing errors within a component, or as fine-grained as showing step-by-step traces of events (like HTTP access logs, pod state changes, controller actions, or scheduler decisions).

> Warning: In contrast to the command line flags described here, the *log output* itself does *not* fall under the Kubernetes API stability guarantees: individual log entries and their formatting may change from one release to the next!

## Klog

klog is the Kubernetes logging library. [klog](https://github.com/kubernetes/klog) generates log messages for the Kubernetes system components.

Kubernetes is in the process of simplifying logging in its components. The following klog command line flags [are deprecated](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components) starting with Kubernetes v1.23 and removed in Kubernetes v1.26:

  • `--add-dir-header`
  • `--alsologtostderr`
  • `--log-backtrace-at`
  • `--log-dir`
  • `--log-file`
  • `--log-file-max-size`
  • `--logtostderr`
  • `--one-output`
  • `--skip-headers`
  • `--skip-log-headers`
  • `--stderrthreshold`

Output will always be written to stderr, regardless of the output format. Output redirection is expected to be handled by the component which invokes a Kubernetes component. This can be a POSIX shell or a tool like systemd.

In some cases, for example a distroless container or a Windows system service, those options are not available. Then the [`kube-log-runner`](https://github.com/kubernetes/kubernetes/blob/d2a8a81639fcff8d1221b900f66d28361a170654/staging/src/k8s.io/component-base/logs/kube-log-runner/README.md) binary can be used as wrapper around a Kubernetes component to redirect output. A prebuilt binary is included in several Kubernetes base images under its traditional name as `/go-runner` and as `kube-log-runner` in server and node release archives.

This table shows how `kube-log-runner` invocations correspond to shell redirection:

| Usage | POSIX shell (such as bash) | `kube-log-runner <options> <cmd>` | | -----------------------------------------|----------------------------|-------------------------------------------------------------| | Merge stderr and stdout, write to stdout | `2>&1` | `kube-log-runner` (default behavior) | | Redirect both into log file | `1>>/tmp/log 2>&1` | `kube-log-runner -log-file=/tmp/log` | | Copy into log file and to stdout | `2>&1 \| tee -a /tmp/log` | `kube-log-runner -log-file=/tmp/log -also-stdout` | | Redirect only stdout into log file | `>/tmp/log` | `kube-log-runner -log-file=/tmp/log -redirect-stderr=false` |

### Klog output

An example of the traditional klog native format:

``` I1025 00:15:15.525108 1 httplog.go:79] GET /api/v1/namespaces/kube-system/pods/metrics-server-v0.3.1-57c75779f-9p8wg: (1.512ms) 200 [pod_nanny/v0.0.0 (linux/amd64) kubernetes/$Format 10.56.1.19:51756] ```

The message string may contain line breaks:

``` I1025 00:15:15.525108 1 example.go:79] This is a message which has a line break. ```

### Structured Logging

> Warning: Migration to structured log messages is an ongoing process. Not all log messages are structured in this version. When parsing log files, you must also handle unstructured log messages.

Log formatting and value serialization are subject to change.

Structured logging introduces a uniform structure in log messages allowing for programmatic extraction of information. You can store and process structured logs with less effort and cost. The code which generates a log message determines whether it uses the traditional unstructured klog out …(trimmed)

Sources

concepts/cluster-administration/system-logs.md · docSystem Logs

Related (14)

references kube-controller-managerkube-controller-manager conf=1
references API serverkube-apiserver conf=1
references kube-schedulerkube-scheduler conf=1
references Kubeletkubelet conf=1
references Container Runtimecontainer runtime conf=1
part_of Klogdescribes conf=1
part_of Log querydescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Klog outputdescribes conf=1
part_of Structured Loggingdescribes conf=1
part_of Contextual Loggingdescribes conf=1
part_of JSON log formatdescribes conf=1
part_of Log verbosity leveldescribes conf=1
part_of Log locationdescribes conf=1

← all Docs