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

Disable kubeadm for filebeat (both filbeat.input and filbeat.autodiscover) #40301

Merged
merged 36 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7ec7a1b
first effort to disable kubeadm for filebeat autodiscover
gizas Jul 19, 2024
e040782
merging with main
gizas Aug 28, 2024
634c37f
merging with main util
gizas Aug 28, 2024
badda64
merging with main test file
gizas Aug 28, 2024
2657b9a
adding kubeadm changes and merging to main
gizas Sep 10, 2024
9cb2e68
adding filebeat
gizas Sep 10, 2024
9f127ca
adding filebeat manifest
gizas Sep 10, 2024
ed5e62f
adding go.sum
gizas Sep 10, 2024
72e8ec2
removing printf
gizas Sep 10, 2024
4301d26
Merge branch 'main' into kubeadm_filebeat
gizas Sep 10, 2024
df80e6f
fixing conflicts
gizas Sep 10, 2024
c57c9a3
fixing conflicts
gizas Sep 10, 2024
c830308
adding Changelog
gizas Sep 10, 2024
f048bb0
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
d05c2ac
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
ea37261
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
a4a9f7f
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
a1a2287
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
ce90016
adding err handling to fix linting errors
gizas Sep 10, 2024
03882cd
Merge branch 'main' into kubeadm_filebeat
gizas Sep 10, 2024
7c53e7e
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
1ea2121
Merge branch 'kubeadm_filebeat' of github.com:elastic/beats into kube…
gizas Sep 10, 2024
3534ecf
adding processor fixes
gizas Sep 10, 2024
f5aff00
adding processor docs
gizas Sep 10, 2024
cef81a6
adding processor docs
gizas Sep 10, 2024
831a647
Update filebeat/_meta/test/docs/01_playground/filebeat.yaml
gizas Sep 10, 2024
3adaadf
Update libbeat/processors/add_kubernetes_metadata/docs/add_kubernetes…
gizas Sep 10, 2024
41ffe1c
Update dev-tools/kubernetes/filebeat/Dockerfile.debug
gizas Sep 10, 2024
47e82d3
fixing docs and adding mericbeat references
gizas Sep 10, 2024
f079b5a
fixing docs and adding mericbeat references
gizas Sep 10, 2024
e3613ac
Merge branch 'main' into kubeadm_filebeat
gizas Sep 13, 2024
69862e3
Update filebeat/_meta/config/filebeat.autodiscover.reference.yml.tmpl
gizas Sep 18, 2024
4489901
Merge branch 'main' of github.com:elastic/beats into kubeadm_filebeat
gizas Sep 18, 2024
b50a0cb
updating docs
gizas Sep 18, 2024
a419fcb
Merge branch 'main' of github.com:elastic/beats into kubeadm_filebeat
gizas Sep 18, 2024
8213010
updating docs
gizas Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Disable event normalization for netflow input {pull}40635[40635]
- Allow attribute selection in the Active Directory entity analytics provider. {issue}40482[40482] {pull}40662[40662]
- Improve error quality when CEL program does not correctly return an events array. {pull}40580[40580]
- Add `use_kubeadm` config option for filebeat (both filbeat.input and autodiscovery) in order to toggle kubeadm-config api requests {pull}40301[40301]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/kubernetes/filebeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@latest

COPY build/filebeat-debugger /usr/share/filebeat/filebeat-debugger

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/kubernetes/heartbeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@latest

COPY build/heartbeat-debugger /usr/share/heartbeat/heartbeat-debugger

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/kubernetes/metricbeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@latest

COPY build/metricbeat-debugger /usr/share/metricbeat/metricbeat-debugger

Expand Down
24 changes: 24 additions & 0 deletions filebeat/_meta/config/filebeat.autodiscover.reference.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,27 @@
# - type: container
# paths:
# - /var/log/containers/*.log

#Example: for kubernetes container logs autodiscovery
# filebeat.autodiscover:
# providers:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# # By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
# use_kubeadm: true
gizas marked this conversation as resolved.
Show resolved Hide resolved
# hints.default_config:
# type: filestream
# id: kubernetes-container-logs-${data.kubernetes.pod.name}-${data.kubernetes.container.id}
# paths:
# - /var/log/containers/*-${data.kubernetes.container.id}.log
# parsers:
# - container: ~
# prospector:
# scanner:
# fingerprint.enabled: true
# symlinks: true
# file_identity.fingerprint: ~

#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
# use_kubeadm: true
28 changes: 23 additions & 5 deletions filebeat/_meta/test/docs/01_playground/filebeat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ metadata:
data:
filebeat.yml: |-
filebeat.inputs:
- type: container
- type: filestream
id: kubernetes-container-logs
paths:
- /var/log/containers/*.log
parsers:
- container: ~
prospector:
scanner:
fingerprint.enabled: true
symlinks: true
file_identity.fingerprint: ~
processors:
- add_kubernetes_metadata:
#use_kubeadm: true
host: ${NODE_NAME}
matchers:
- logs_path:
Expand All @@ -25,10 +34,19 @@ data:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# #use_kubeadm: true
# hints.default_config:
# type: container
# type: filestream
# id: kubernetes-container-logs-${data.kubernetes.pod.name}-${data.kubernetes.container.id}
# paths:
# - /var/log/containers/*${data.kubernetes.container.id}.log
# - /var/log/containers/*-${data.kubernetes.container.id}.log
# parsers:
# - container: ~
# prospector:
# scanner:
# fingerprint.enabled: true
# symlinks: true
# file_identity.fingerprint: ~
gizas marked this conversation as resolved.
Show resolved Hide resolved
processors:
- add_cloud_metadata:
Expand Down Expand Up @@ -64,12 +82,12 @@ spec:
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: filebeat
image: docker.elastic.co/beats/filebeat:8.0.0-SNAPSHOT
image: docker.elastic.co/beats/filebeat:8.16.0-SNAPSHOT
command: [ "sleep" ]
args: [ "infinity" ]
env:
- name: ELASTICSEARCH_HOST
value: elasticsearch.default.svc.cluster.local
value: elasticsearch
- name: ELASTICSEARCH_PORT
value: "9200"
- name: ELASTICSEARCH_USERNAME
Expand Down
24 changes: 24 additions & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,30 @@ filebeat.inputs:
# paths:
# - /var/log/containers/*.log

#Example: for kubernetes container logs autodiscovery
# filebeat.autodiscover:
# providers:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# # By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
# use_kubeadm: true
# hints.default_config:
# type: filestream
# id: kubernetes-container-logs-${data.kubernetes.pod.name}-${data.kubernetes.container.id}
# paths:
# - /var/log/containers/*-${data.kubernetes.container.id}.log
# parsers:
# - container: ~
# prospector:
# scanner:
# fingerprint.enabled: true
# symlinks: true
# file_identity.fingerprint: ~

#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
# use_kubeadm: true

# ========================== Filebeat global options ===========================

# Registry data path. If a relative path is used, it is considered relative to the
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var AllSupportedHints = []string{"enabled", "module", "metricsets", "hosts", "pe
type Config struct {
KubeConfig string `config:"kube_config"`
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
KubeAdm bool `config:"use_kubeadm"`

Namespace string `config:"namespace"`
SyncPeriod time.Duration `config:"sync_period"`
Expand Down Expand Up @@ -71,6 +72,7 @@ var DefaultCleanupTimeout time.Duration = 0
func defaultConfig() *Config {
return &Config{
SyncPeriod: 10 * time.Minute,
KubeAdm: true,
Resource: "pod",
CleanupTimeout: DefaultCleanupTimeout,
Prefix: "co.elastic",
Expand Down
9 changes: 9 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish fu
}

metaConf := config.AddResourceMetadata
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
err = metaConf.Namespace.SetBool("use_kubeadm", -1, config.KubeAdm)
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added due to go-lint errors

logger.Errorf("couldn't set kubeadm variable for namespace due to error %+v", err)
}
err = metaConf.Node.SetBool("use_kubeadm", -1, config.KubeAdm)
if err != nil {
logger.Errorf("couldn't set kubeadm variable for node due to error %+v", err)
}

if metaConf.Node.Enabled() || config.Hints.Enabled() {
options := kubernetes.WatchOptions{
Expand Down
5 changes: 5 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func NewServiceEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publis
var namespaceWatcher kubernetes.Watcher

metaConf := config.AddResourceMetadata
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
err = metaConf.Namespace.SetBool("use_kubeadm", -1, config.KubeAdm)
if err != nil {
logger.Errorf("couldn't set kubeadm variable for namespace due to error %+v", err)
}

if metaConf.Namespace.Enabled() || config.Hints.Enabled() {
namespaceWatcher, err = kubernetes.NewNamedWatcher("namespace", client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
Expand Down
1 change: 1 addition & 0 deletions libbeat/processors/add_kubernetes_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type kubeAnnotatorConfig struct {
KubeConfig string `config:"kube_config"`
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
KubeAdm bool `config:"use_kubeadm"`
Node string `config:"node"`
Scope string `config:"scope"`
Namespace string `config:"namespace"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Example:
-------------------------------------------------------------------------------------
`kube_config`:: (Optional) Use given config file as configuration for Kubernetes
client. It defaults to `KUBECONFIG` environment variable if present.
`use_kubeadm`:: (Optional) Default true. By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
`kube_client_options`:: (Optional) Additional options can be configured for Kubernetes
client. Currently client QPS and burst are supported, if not set Kubernetes client's
https://pkg.go.dev/k8s.io/client-go/rest#pkg-constants[default QPS and burst] will be used.
Expand Down
9 changes: 9 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (k *kubernetesAnnotator) init(config kubeAnnotatorConfig, cfg *config.C) {
k.initOnce.Do(func() {
var replicaSetWatcher, jobWatcher, namespaceWatcher, nodeWatcher kubernetes.Watcher

// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
err := config.AddResourceMetadata.Namespace.SetBool("use_kubeadm", -1, config.KubeAdm)
if err != nil {
k.log.Errorf("couldn't set kubeadm variable for namespace due to error %+v", err)
}
err = config.AddResourceMetadata.Node.SetBool("use_kubeadm", -1, config.KubeAdm)
if err != nil {
k.log.Errorf("couldn't set kubeadm variable for node due to error %+v", err)
}
client, err := kubernetes.GetKubernetesClient(config.KubeConfig, config.KubeClientOptions)
if err != nil {
if kubernetes.IsInCluster(config.KubeConfig) {
Expand Down
14 changes: 14 additions & 0 deletions metricbeat/docs/modules/kubernetes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
#include_labels: []
#exclude_labels: []
#include_annotations: []
Expand Down Expand Up @@ -286,6 +288,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
#include_labels: []
#exclude_labels: []
#include_annotations: []
Expand Down Expand Up @@ -326,6 +330,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
# Set the namespace to watch for events
#namespace: staging
# Set the sync period of the watchers
Expand All @@ -346,6 +352,8 @@ metricbeat.modules:
ssl.certificate_authorities:
- /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
period: 30s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
# Kubernetes proxy server
# (when running metricbeat locally at hosts or as a daemonset + host network)
Expand All @@ -355,6 +363,8 @@ metricbeat.modules:
- proxy
hosts: ["localhost:10249"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
# Kubernetes controller manager
# (URL and deployment method should be adapted to match the controller manager deployment / service / endpoint)
Expand All @@ -364,6 +374,8 @@ metricbeat.modules:
- controllermanager
hosts: ["http://localhost:10252"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
# Kubernetes scheduler
# (URL and deployment method should be adapted to match scheduler deployment / service / endpoint)
Expand All @@ -373,6 +385,8 @@ metricbeat.modules:
- scheduler
hosts: ["localhost:10251"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
Expand Down
14 changes: 14 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
#include_labels: []
#exclude_labels: []
#include_annotations: []
Expand Down Expand Up @@ -573,6 +575,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
#include_labels: []
#exclude_labels: []
#include_annotations: []
Expand Down Expand Up @@ -613,6 +617,8 @@ metricbeat.modules:
# If kube_config is not set, KUBECONFIG environment variable will be checked
# and if not present it will fall back to InCluster
#kube_config: ~/.kube/config
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true
# Set the namespace to watch for events
#namespace: staging
# Set the sync period of the watchers
Expand All @@ -633,6 +639,8 @@ metricbeat.modules:
ssl.certificate_authorities:
- /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
period: 30s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true

# Kubernetes proxy server
# (when running metricbeat locally at hosts or as a daemonset + host network)
Expand All @@ -642,6 +650,8 @@ metricbeat.modules:
- proxy
hosts: ["localhost:10249"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true

# Kubernetes controller manager
# (URL and deployment method should be adapted to match the controller manager deployment / service / endpoint)
Expand All @@ -651,6 +661,8 @@ metricbeat.modules:
- controllermanager
hosts: ["http://localhost:10252"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true

# Kubernetes scheduler
# (URL and deployment method should be adapted to match scheduler deployment / service / endpoint)
Expand All @@ -660,6 +672,8 @@ metricbeat.modules:
- scheduler
hosts: ["localhost:10251"]
period: 10s
#By default requests to kubeadm config map are made in order to enrich cluster name by requesting /api/v1/namespaces/kube-system/configmaps/kubeadm-config API endpoint.
use_kubeadm: true

#--------------------------------- KVM Module ---------------------------------
- module: kvm
Expand Down
Loading
Loading