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

Add k8s manifest leveraging leaderelection #20512

Merged
merged 7 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
49 changes: 43 additions & 6 deletions deploy/kubernetes/metricbeat-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,47 @@ data:
# Reload module configs as they change:
reload.enabled: false

# To enable hints based autodiscover uncomment this:
#metricbeat.autodiscover:
# providers:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
metricbeat.autodiscover:
providers:
# To enable hints based autodiscover uncomment this:
#- type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# Uncomment the following to enable leader election provider that handles
# singleton instance configuration across the Daemonset Pods of the whole cluster
# in order to monitor some unique data sources, like kube-state-metrics.
# When enabling this remember to also delete the Deployment or just set the replicas of the
# Deployment to 0.
Comment on lines +23 to +27
Copy link

Choose a reason for hiding this comment

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

This is too much wording IMO, if we do the docs right this should only be

# uncomment the following to enable collection from kube-state-metrics

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I will try to improve it

#- type: kubernetes
# scope: cluster
# node: ${NODE_NAME}
# unique: true
# # identifier: <lease_lock_name>
Copy link

Choose a reason for hiding this comment

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

This might be confusing: under which circumstances should I uncomment? What the value should be in that case?
I'd remove this line altogether.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I will remove it

# templates:
# - config:
# - module: kubernetes
# hosts: ["kube-state-metrics:8080"]
# period: 10s
# add_metadata: true
# metricsets:
# - state_node
# - state_deployment
# - state_replicaset
# - state_pod
# - state_container
# - state_cronjob
# - state_resourcequota
# - state_statefulset
# # Uncomment this to get k8s events:
# #- event
# - module: kubernetes
# metricsets:
# - apiserver
# hosts: ["https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}"]
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
# ssl.certificate_authorities:
# - /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
# period: 30s

processors:
- add_cloud_metadata:
Expand Down Expand Up @@ -258,6 +293,8 @@ metadata:
labels:
k8s-app: metricbeat
spec:
# Set to 0 if using leader election provider with the Daemonset
Copy link

Choose a reason for hiding this comment

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

What happens if we remove the Deployment instead? I don't think the UX is great here...

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 Removing the deployment completely will have the same result -> 0 Deployment Pods.

replicas: 1
selector:
matchLabels:
k8s-app: metricbeat
Expand Down
47 changes: 41 additions & 6 deletions deploy/kubernetes/metricbeat/metricbeat-daemonset-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,47 @@ data:
# Reload module configs as they change:
reload.enabled: false

# To enable hints based autodiscover uncomment this:
#metricbeat.autodiscover:
# providers:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
metricbeat.autodiscover:
providers:
# To enable hints based autodiscover uncomment this:
#- type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# Uncomment the following to enable leader election provider that handles
# singleton instance configuration across the Daemonset Pods of the whole cluster
# in order to monitor some unique data sources, like kube-state-metrics.
# When enabling this remember to also delete the Deployment or just set the replicas of the
# Deployment to 0.
#- type: kubernetes
# scope: cluster
# node: ${NODE_NAME}
# unique: true
# # identifier: <lease_lock_name>
# templates:
# - config:
# - module: kubernetes
# hosts: ["kube-state-metrics:8080"]
# period: 10s
# add_metadata: true
# metricsets:
# - state_node
# - state_deployment
# - state_replicaset
# - state_pod
# - state_container
# - state_cronjob
# - state_resourcequota
# - state_statefulset
# # Uncomment this to get k8s events:
# #- event
# - module: kubernetes
# metricsets:
# - apiserver
# hosts: ["https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}"]
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
# ssl.certificate_authorities:
# - /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
# period: 30s

processors:
- add_cloud_metadata:
Expand Down
2 changes: 2 additions & 0 deletions deploy/kubernetes/metricbeat/metricbeat-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ metadata:
labels:
k8s-app: metricbeat
spec:
# Set to 0 if using leader election provider with the Daemonset
replicas: 1
selector:
matchLabels:
k8s-app: metricbeat
Expand Down
41 changes: 41 additions & 0 deletions metricbeat/docs/running-on-kubernetes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,44 @@ metricbeat 1 1 1 1 1m
------------------------------------------------

Metrics should start flowing to Elasticsearch.


[float]
==== Deploying Metricbeat Daemonset with Leader Election enabled

In some cases users may want to avoid deploying both a Deployment and a Daemonset
to collect cluser-wide metrics and node-level metrics.
For this case, we provide the option to deploy Metricbeat only as a Daemonset
and leverage the leader election feature which allows to define configurations
that are enabled only by the leader Pod. The leader Pod is automatically chosen
between the Pods of the Daemonset.
Here is an example of a configuration that enables leader election:
[source,yaml]
-----
metricbeat.autodiscover:
providers:
- type: kubernetes
scope: cluster
node: ${NODE_NAME}
unique: true
identifier: leaderelectionmetricbeat
templates:
- config:
- module: kubernetes
hosts: ["kube-state-metrics:8080"]
period: 10s
add_metadata: true
metricsets:
- state_node
-----
Users can find more info about the `unique` and `identifier` options at <<configuration-autodiscover>>.

Users can enable the respective parts the Daemonset ConfigMap and
set the `replicas` of the Deployment to `0` in order to only deploy
the Daemonset on the cluster with the leader election provider enabled
in order to collect cluster-wide metrics:
Comment on lines +232 to +235
Copy link

Choose a reason for hiding this comment

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

@ChrsMark Something doesn't work with the wording here, we should make this statement a bit clearer

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

["source", "sh", subs="attributes"]
------------------------------------------------
curl -L -O https://raw.githubusercontent.com/elastic/beats/{branch}/deploy/kubernetes/metricbeat-kubernetes.yaml
kubectl create -f metricbeat-kubernetes.yaml
------------------------------------------------