Kubernetes logs
Collect logs from Kubernetes Nodes
Requirements
>= 1.19
is required./var/log/pods
directory. When run in a
Kubernetes cluster this can be provided with a hostPath volume.Warnings
This source is only tested on Linux. Your mileage may vary for clusters on Windows.
Configuration
Example configurations
{
"sources": {
"my_source_id": {
"type": "kubernetes_logs"
}
}
}
[sources.my_source_id]
type = "kubernetes_logs"
sources:
my_source_id:
type: kubernetes_logs
{
"sources": {
"my_source_id": {
"type": "kubernetes_logs",
"auto_partial_merge": true,
"data_dir": "/var/local/lib/vector/",
"delay_deletion_ms": 60000,
"exclude_paths_glob_patterns": [
"**/exclude/**"
],
"extra_field_selector": "metadata.name!=pod-name-to-exclude",
"extra_label_selector": "my_custom_label!=my_value",
"extra_namespace_label_selector": "my_custom_label!=my_value",
"fingerprint_lines": 1,
"glob_minimum_cooldown_ms": 60000,
"ignore_older_secs": 600,
"include_paths_glob_patterns": [
"**/include/**"
],
"ingestion_timestamp_field": ".ingest_timestamp",
"kube_config_file": "/path/to/.kube/config",
"max_line_bytes": 32768,
"max_read_bytes": 2048,
"oldest_first": true,
"read_from": "beginning",
"rotate_wait_secs": 9223372036854776000,
"self_node_name": "${VECTOR_SELF_NODE_NAME}",
"timezone": "local"
}
}
}
[sources.my_source_id]
type = "kubernetes_logs"
auto_partial_merge = true
data_dir = "/var/local/lib/vector/"
delay_deletion_ms = 60_000
exclude_paths_glob_patterns = [ "**/exclude/**" ]
extra_field_selector = "metadata.name!=pod-name-to-exclude"
extra_label_selector = "my_custom_label!=my_value"
extra_namespace_label_selector = "my_custom_label!=my_value"
fingerprint_lines = 1
glob_minimum_cooldown_ms = 60_000
ignore_older_secs = 600
include_paths_glob_patterns = [ "**/include/**" ]
ingestion_timestamp_field = ".ingest_timestamp"
kube_config_file = "/path/to/.kube/config"
max_line_bytes = 32_768
max_read_bytes = 2_048
oldest_first = true
read_from = "beginning"
rotate_wait_secs = 9_223_372_036_854_776_000
self_node_name = "${VECTOR_SELF_NODE_NAME}"
timezone = "local"
sources:
my_source_id:
type: kubernetes_logs
auto_partial_merge: true
data_dir: /var/local/lib/vector/
delay_deletion_ms: 60000
exclude_paths_glob_patterns:
- "**/exclude/**"
extra_field_selector: metadata.name!=pod-name-to-exclude
extra_label_selector: my_custom_label!=my_value
extra_namespace_label_selector: my_custom_label!=my_value
fingerprint_lines: 1
glob_minimum_cooldown_ms: 60000
ignore_older_secs: 600
include_paths_glob_patterns:
- "**/include/**"
ingestion_timestamp_field: .ingest_timestamp
kube_config_file: /path/to/.kube/config
max_line_bytes: 32768
max_read_bytes: 2048
oldest_first: true
read_from: beginning
rotate_wait_secs: 9223372036854776000
self_node_name: ${VECTOR_SELF_NODE_NAME}
timezone: local
auto_partial_merge
optional boolWhether or not to automatically merge partial events.
Partial events are messages that were split by the Kubernetes Container Runtime log driver.
true
data_dir
optional string literalThe directory used to persist file checkpoint positions.
By default, the global data_dir
option is used.
Make sure the running user has write permissions to this directory.
If this directory is specified, then Vector will attempt to create it.
delay_deletion_ms
optional uintHow long to delay removing metadata entries from the cache when a pod deletion event event is received from the watch stream.
A longer delay allows for continued enrichment of logs after the originating Pod is removed. If relevant metadata has been removed, the log is forwarded un-enriched and a warning is emitted.
60000
(milliseconds)exclude_paths_glob_patterns
optional [string][**/*.gz **/*.tmp]
extra_field_selector
optional string literalSpecifies the field selector to filter Pods with, to be used in addition to the built-in Node filter.
The built-in Node filter uses self_node_name
to only watch Pods located on the same Node.
extra_label_selector
optional string literalextra_namespace_label_selector
optional string literalfingerprint_lines
optional uintThe number of lines to read for generating the checksum.
If your files share a common header that is not always a fixed size,
If the file has less than this amount of lines, it won’t be read at all.
1
(lines)glob_minimum_cooldown_ms
optional uintThe interval at which the file system is polled to identify new files to read from.
This is quite efficient, yet might still create some load on the file system; in addition, it is currently coupled with checksum dumping in the underlying file server, so setting it too low may introduce a significant overhead.
60000
(milliseconds)ignore_older_secs
optional uintinclude_paths_glob_patterns
optional [string][**/*]
ingestion_timestamp_field
optional string literalOverrides the name of the log field used to add the ingestion timestamp to each event.
This is useful to compute the latency between important event processing
stages. For example, the time delta between when a log line was written and when it was
processed by the kubernetes_logs
source.
internal_metrics
optional objectinternal_metrics.include_file_tag
optional boolWhether or not to include the “file” tag on the component’s corresponding internal metrics.
This is useful for distinguishing between different files while monitoring. However, the tag’s cardinality is unbounded.
false
kube_config_file
optional string literalOptional path to a readable kubeconfig file.
If not set, a connection to Kubernetes is made using the in-cluster configuration.
max_line_bytes
optional uintThe maximum number of bytes a line can contain before being discarded.
This protects against malformed lines or tailing incorrect files.
32768
(bytes)max_read_bytes
optional uintMax amount of bytes to read from a single file before switching over to the next file.
Note: This does not apply when oldest_first
is true
.
This allows distributing the reads more or less evenly across the files.
2048
(bytes)namespace_annotation_fields
optional objectnamespace_annotation_fields.namespace_labels
optional string literalEvent field for the Namespace’s labels.
Set to ""
to suppress this key.
.kubernetes.namespace_labels
node_annotation_fields
optional objectnode_annotation_fields.node_labels
optional string literalEvent field for the Node’s labels.
Set to ""
to suppress this key.
.kubernetes.node_labels
oldest_first
optional booltrue
pod_annotation_fields
optional objectpod_annotation_fields.container_id
optional string literalEvent field for the Container’s ID.
Set to ""
to suppress this key.
.kubernetes.container_id
pod_annotation_fields.container_image
optional string literalEvent field for the Container’s image.
Set to ""
to suppress this key.
.kubernetes.container_image
pod_annotation_fields.container_image_id
optional string literalEvent field for the Container’s image ID.
Set to ""
to suppress this key.
.kubernetes.container_image_id
pod_annotation_fields.container_name
optional string literalEvent field for the Container’s name.
Set to ""
to suppress this key.
.kubernetes.container_name
pod_annotation_fields.pod_annotations
optional string literalEvent field for the Pod’s annotations.
Set to ""
to suppress this key.
.kubernetes.pod_annotations
pod_annotation_fields.pod_ip
optional string literalEvent field for the Pod’s IPv4 address.
Set to ""
to suppress this key.
.kubernetes.pod_ip
pod_annotation_fields.pod_ips
optional string literalEvent field for the Pod’s IPv4 and IPv6 addresses.
Set to ""
to suppress this key.
.kubernetes.pod_ips
pod_annotation_fields.pod_labels
optional string literalEvent field for the Pod
’s labels.
Set to ""
to suppress this key.
.kubernetes.pod_labels
pod_annotation_fields.pod_name
optional string literalEvent field for the Pod’s name.
Set to ""
to suppress this key.
.kubernetes.pod_name
pod_annotation_fields.pod_namespace
optional string literalEvent field for the Pod’s namespace.
Set to ""
to suppress this key.
.kubernetes.pod_namespace
pod_annotation_fields.pod_node_name
optional string literalEvent field for the Pod’s node_name.
Set to ""
to suppress this key.
.kubernetes.pod_node_name
pod_annotation_fields.pod_owner
optional string literalEvent field for the Pod’s owner reference.
Set to ""
to suppress this key.
.kubernetes.pod_owner
pod_annotation_fields.pod_uid
optional string literalEvent field for the Pod’s UID.
Set to ""
to suppress this key.
.kubernetes.pod_uid
read_from
optional string literal enumOption | Description |
---|---|
beginning | Read from the beginning of the file. |
end | Start reading from the current end of the file. |
beginning
rotate_wait_secs
optional uint9.223372036854776e+18
(seconds)self_node_name
optional string literalThe name of the Kubernetes Node that is running.
Configured to use an environment variable by default, to be evaluated to a value provided by Kubernetes at Pod creation.
${VECTOR_SELF_NODE_NAME}
timezone
optional string literaluse_apiserver_cache
optional boolfalse
Outputs
<component_id>
Output Data
Logs
Warning
Line
Pod
log file./var/log/pods/pod-namespace_pod-name_pod-uid/container/1.log
docker://f24c81dcd531c5d353751c77fe0556a4f602f7714c72b9a58f9b26c0628f1fa6
busybox:1.30
busybox@sha256:1e7b63c09af457b93c17d25ef4e6aee96b5bb95f087840cffd7c4bb2fe8ae5c6
coredns
{
"mylabel": "myvalue"
}
{
"myannotation": "myvalue"
}
192.168.1.1
192.168.1.1
::1
{
"mylabel": "myvalue"
}
coredns-qwertyuiop-qwert
kube-system
minikube
ReplicaSet/coredns-565d847f94
ba46d8c9-9541-4f6b-bbf9-d23b36f2f136
53.126.150.246 - - [01/Oct/2020:11:25:58 -0400] "GET /disintermediate HTTP/2.0" 401 20308
kubernetes_logs
stdout
stderr
2020-10-10T17:07:36.452332Z
Telemetry
Metrics
linkcomponent_discarded_events_total
counterfilter
transform, or false if due to an error.component_errors_total
countercomponent_received_bytes_total
countercomponent_received_event_bytes_total
countercomponent_received_events_count
histogramA histogram of the number of events passed in each internal batch in Vector’s internal topology.
Note that this is separate than sink-level batching. It is mostly useful for low level debugging performance issues in Vector due to small internal batches.
component_received_events_total
countercomponent_sent_event_bytes_total
countercomponent_sent_events_total
counterk8s_docker_format_parse_failures_total
counterk8s_format_picker_edge_cases_total
countersource_lag_time_seconds
histogramExamples
Sample Output
Given this event...F1015 11:01:46.499073 1 main.go:39] error getting server version: Get "https://10.96.0.1:443/version?timeout=32s": dial tcp 10.96.0.1:443: connect: network is unreachable
sources:
my_source_id:
type: kubernetes_logs
[sources.my_source_id]
type = "kubernetes_logs"
{
"sources": {
"my_source_id": {
"type": "kubernetes_logs"
}
}
}
{
"file": "/var/log/pods/kube-system_storage-provisioner_93bde4d0-9731-4785-a80e-cd27ba8ad7c2/storage-provisioner/1.log",
"kubernetes.container_image": "gcr.io/k8s-minikube/storage-provisioner:v3",
"kubernetes.container_name": "storage-provisioner",
"kubernetes.namespace_labels": {
"kubernetes.io/metadata.name": "kube-system"
},
"kubernetes.pod_annotations": {
"prometheus.io/scrape": "false"
},
"kubernetes.pod_ip": "192.168.1.1",
"kubernetes.pod_ips": [
"192.168.1.1",
"::1"
],
"kubernetes.pod_labels": {
"addonmanager.kubernetes.io/mode": "Reconcile",
"gcp-auth-skip-secret": "true",
"integration-test": "storage-provisioner"
},
"kubernetes.pod_name": "storage-provisioner",
"kubernetes.pod_namespace": "kube-system",
"kubernetes.pod_node_name": "minikube",
"kubernetes.pod_uid": "93bde4d0-9731-4785-a80e-cd27ba8ad7c2",
"message": "F1015 11:01:46.499073 1 main.go:39] error getting server version: Get \"https://10.96.0.1:443/version?timeout=32s\": dial tcp 10.96.0.1:443: connect: network is unreachable",
"source_type": "kubernetes_logs",
"stream": "stderr",
"timestamp": "2020-10-15T11:01:46.499555308Z"
}
How it works
Checkpointing
data_dir
option, but can be overridden
via the data_dir
option in the file source directly.Container exclusion
The kubernetes_logs
source
can skip the logs from the individual Containers of a particular
Pod. Add an annotation vector.dev/exclude-containers
to the
Pod, and enumerate the names of all the Containers to exclude in
the value of the annotation like so:
vector.dev/exclude-containers: "container1,container2"
This annotation will make Vector skip logs originating from the container1 and container2 of the Pod marked with the annotation, while logs from other Containers in the Pod will still be collected.
Enrichment
kubernetes_logs
source output docs.Filtering
Vector provides rich filtering options for Kubernetes log collection:
- Built-in Pod and Container exclusion rules.
- The
include_paths_glob_patterns
option allows you to include Kubernetes log files by the file name and path. - The
exclude_paths_glob_patterns
option allows you to exclude Kubernetes log files by the file name and path. - The
include_paths_glob_patterns
option defaults toinclude all
and is evaluated before theexclude_paths_glob_patterns
option. - The
extra_field_selector
option specifies the field selector to filter Pods with, to be used in addition to the built-in Node filter. - The
extra_label_selector
option specifies the label selector to filter Pods with, to be used in addition to the built-invector.dev/exclude
filter.
Globbing
By default, the kubernetes_logs
source
ignores compressed and temporary files. This behavior can be configured with the
exclude_paths_glob_patterns
option.
Globbing is used to continually discover Pods’ log files
at a rate defined by the glob_minimum_cooldown
option. In environments when files are
rotated rapidly, we recommend lowering the glob_minimum_cooldown
to catch files
before they are compressed.
Kubernetes API access control
Vector requires access to the Kubernetes API.
Specifically, the kubernetes_logs
source
uses the /api/v1/pods
, /api/v1/namespaces
, and /api/v1/nodes
endpoints
to list
and watch
resources we use to enrich events with additional metadata.
Modern Kubernetes clusters run with RBAC (role-based access control)
scheme. RBAC-enabled clusters require some configuration to grant Vector
the authorization to access the Kubernetes API endpoints. As RBAC is
currently the standard way of controlling access to the Kubernetes API,
we ship the necessary configuration out of the box: see the ClusterRole, ClusterRoleBinding,
and ServiceAccount in our Kubectl YAML
config, and the rbac.yaml
template configuration of the Helm chart.
If your cluster doesn’t use any access control scheme and doesn’t restrict access to the Kubernetes API, you don’t need to do any extra configuration - Vector will just work.
Clusters using legacy ABAC scheme are not officially supported
(although Vector might work if you configure access properly) -
we encourage switching to RBAC. If you use a custom access control
scheme - make sure Vector’s Pod/ServiceAccount is granted list
and watch
access
to the /api/v1/pods
, /api/v1/namespaces
, and /api/v1/nodes
resources.
Kubernetes API communication
Vector communicates with the Kubernetes API to enrich the data it collects with Kubernetes context. Therefore, Vector must have access to communicate with the Kubernetes API server. If Vector is running in a Kubernetes cluster then Vector will connect to that cluster using the Kubernetes provided access information.
In addition to access, Vector implements proper desync handling to ensure communication is safe and reliable. This ensures that Vector will not overwhelm the Kubernetes API or compromise its stability.
Namespace exclusion
kubernetes_logs
source
will skip logs from the Namespaces that have a vector.dev/exclude: "true"
label.
You can configure additional exclusion rules via label selectors,
see the available options.Partial message merging
reduce
transform which offers
the ability to handle custom merging of things like
stacktraces.Pod exclusion
kubernetes_logs
source
will skip logs from the Pods that have a vector.dev/exclude: "true"
label.
You can configure additional exclusion rules via label or field selectors,
see the available options.Pod removal
Resource limits
Agent resource limits
If deploy Vector as an agent (collecting data for each of your Nodes), then we recommend the following limits:
resources:
requests:
memory: "64Mi"
cpu: "500m"
limits:
memory: "1024Mi"
cpu: "6000m"
As with all Kubernetes resource limit recommendations, use these as a reference point and adjust as necessary. If your configured Vector pipeline is complex, you may need more resources; if you have a more straightforward pipeline, you may need less.