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

Run EA container + managed by fleet + standalone + autodiscovery #2366

Merged
merged 18 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ed91154
Run EA container + managed by fleet + standalone + autodiscovery
constanca-m Nov 15, 2022
fda02ee
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 16, 2022
3c1a6c0
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 16, 2022
8943aae
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 16, 2022
857accd
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 16, 2022
849203d
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 16, 2022
2a83c6e
Update docs/en/ingest-management/elastic-agent/run-container-common/d…
constanca-m Nov 16, 2022
761cb1b
Apply suggestions.
constanca-m Nov 17, 2022
19cd7c5
Corrected Pod to pod on yaml
constanca-m Nov 17, 2022
4f97593
Changed provider link on autodiscover.
constanca-m Nov 18, 2022
65c4376
Update docs/en/ingest-management/elastic-agent/running-on-kubernetes-…
constanca-m Nov 18, 2022
c9303ff
Update docs/en/ingest-management/elastic-agent/running-on-kubernetes-…
constanca-m Nov 18, 2022
5fc2303
Update docs/en/ingest-management/elastic-agent/running-on-kubernetes-…
constanca-m Nov 18, 2022
ee84ed9
Update docs/en/ingest-management/elastic-agent/running-on-kubernetes-…
constanca-m Nov 18, 2022
055f367
Update docs/en/ingest-management/elastic-agent/configuration/autodisc…
constanca-m Nov 21, 2022
54f9253
Some corrections.
constanca-m Nov 21, 2022
0127865
Removed unnecessary annotations.
constanca-m Nov 21, 2022
bb85343
Merge branch 'main' into update-docs
constanca-m Nov 21, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[elastic-agent-kubernetes-autodiscovery]]
= Kubernetes autodiscovery with {agent}

To use autodiscovery, you will need to modify the manifest file of the {agent}. Refer to <<running-on-kubernetes-standalone>> to learn how to retrieve and configure it.

constanca-m marked this conversation as resolved.
Show resolved Hide resolved
There are two different ways to use autodiscovery:

* <<conditions-based-autodiscover>>

* <<hints-annotations-autodiscovery>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
[[conditions-based-autodiscover]]
= Conditions based autodiscover

You can define autodiscover conditions in each input to allow {agent} to automatically identify Pods and start monitoring them using predefined integrations. You can find more about these inputs and their configurations <<elastic-agent-input-configuration,here>>.
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

== Example: Target pods by host and label
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

To automatically identify a Redis Pod and monitor it with the Redis integration, uncomment the following input configuration inside the {agent} Standalone manifest [here](https://github.com/elastic/elastic-agent/blob/main/deploy/kubernetes/elastic-agent-standalone-kubernetes.yaml):
constanca-m marked this conversation as resolved.
Show resolved Hide resolved


[source,yaml]
------------------------------------------------
- name: redis
type: redis/metrics
use_output: default
meta:
package:
name: redis
version: 0.3.6
data_stream:
namespace: default
streams:
- data_stream:
dataset: redis.info
type: metrics
metricsets:
- info
hosts:
- '${kubernetes.pod.ip}:6379'
idle_timeout: 20s
maxconn: 10
network: tcp
period: 10s
condition: ${kubernetes.labels.app} == 'redis'
------------------------------------------------

The condition `${kubernetes.labels.app} == 'redis'` will make the {agent} look for a Pod with the `redis` label app within the scope defined in its manifest. You can find the exported fields of the Kubernetes integration {metricbeat-ref}/exported-fields-kubernetes-processor.html[here].
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

The `redis` input defined in the {agent} manifest only has `info` as metricset. You can find more metricsets in the {metricbeat-ref}/metricbeat-module-redis.html[Redis module page], as well as the configuration options.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The `redis` input defined in the {agent} manifest only has `info` as metricset. You can find more metricsets in the {metricbeat-ref}/metricbeat-module-redis.html[Redis module page], as well as the configuration options.
The `redis` input defined in the {agent} manifest only specifies the`info` metricset. To learn about other available metricsets and their configuration settings, refer to the {metricbeat-ref}/metricbeat-module-redis.html[Redis module page].

Again I think it will be confusing to users that we point to the module docs, but I don't have a better solution our standalone config docs are incomplete. :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed that is another good example that we refer to metricsets but we dont explain how agent uses them under the hood.

@dedemorton does it make sense to give as a note here a small explanation what metricset term is? or it becomes confusing?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dedemorton #2384 relevant issue to track processors.
We can follow discussion there but is not urgent

Copy link
Contributor

Choose a reason for hiding this comment

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

@gizas I've commented on your request. I'm actually working on the processors documentation right now.

Copy link
Contributor

@dedemorton dedemorton Nov 18, 2022

Choose a reason for hiding this comment

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

does it make sense to give as a note here a small explanation what metricset term is? or it becomes confusing?

Actually I think we should be using "dataset" here because that's the correct term to use when talking about Elastic Agent integrations. We are just in a really awkward position right now because the standalone configuration docs are incomplete (a deliberate decision by management to prioritize the Fleet docs over standalone because we have limited resources to work on all the docs).


To deploy Redis, you can apply the following example manifest:

[source,yaml]
------------------------------------------------
apiVersion: v1
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
kind: ConfigMap
metadata:
name: test-redis-config
data:
redis-config: |
maxmemory 2mb
maxmemory-policy allkeys-lru
---
apiVersion: v1
kind: Pod
metadata:
name: redis
labels:
k8s-app: redis
app: redis
spec:
containers:
- name: redis
image: redis:5.0.4
command:
- redis-server
- "/redis-master/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: test-redis-config
items:
- key: redis-config
path: redis.conf
------------------------------------------------

You should now be able to see Redis data flowing in on index `metrics-redis.info-default`. Make sure that the port on your Redis manifest file and the one used in the Redis input match. Note that at this point all the assets (dashboards, ingest pipelines, and so on) related to the Redis integration are not installed. You need to explicitly <<install-uninstall-integration-assets,install them through Kibana>>.
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

== Example: Target pods by label
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

WARNING: In some "As a Service" Kubernetes implementations, like GKE, the control plane nodes or even the pods running on them won’t be visible. In these cases, it won’t be possible to use scheduler metricsets, necessary for this example. Refer https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-module-kubernetes.html#_scheduler_and_controllermanager[here] to find more information.
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

To set the target host dynamically only for a targeted Pod based on its labels, use a variable in the
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
{agent} policy to return path information from the provider:

[source,yaml]
----
- data_stream:
dataset: kubernetes.scheduler
type: metrics
metricsets:
- scheduler
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
hosts:
- 'https://${kubernetes.pod.ip}:10259'
period: 10s
ssl.verification_mode: none
condition: ${kubernetes.labels.component} == 'kube-scheduler'
----

If you now deploy another Redis pod with a different port, it should be detected. You can check this by, for example, studying the field `service.address` under `metrics-redis.info-default`. It should now display 2 different services.
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

How Redis is relevant here? Right before we are talking about scheduler 🤔 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote about that to give the user the chance to check how that works. I rephrased a little bit to make it more clear: "Following the Redis example, if you deploy another Redis Pod with a different port, it should be detected. To check this, go, for example, to the field service.address under metrics-redis.info-default. It should be displaying two different services.". But even if this doesn't make sense now, we can remove it. What do you think?


To obtain the policy generated by this configuration get inside the {agent} container:
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

["source", "sh", subs="attributes"]
------------------------------------------------
kubectl exec -n kube-system --stdin --tty elastic-agent-standalone-id -- /bin/bash
------------------------------------------------

Do not forget to change the `elastic-agent-standalone-id` to your {agent} pod's name. Moreover, make sure that your pod is inside `kube-system`. If not, change `-n kube-system` to the right namespace.
constanca-m marked this conversation as resolved.
Show resolved Hide resolved

Inside the container <<elastic-agent-cmd-options, inspect the output>> of the configuration file you used for the {agent}:

["source", "sh", subs="attributes"]
------------------------------------------------
elastic-agent inspect output -o default -c /etc/elastic-agent/agent.yml
------------------------------------------------
You should now be able to see the generated policy. If you look for the `scheduler`, it will look similar to this:

[source,yaml]
----
- bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
hosts:
- https://172.19.0.2:10259
index: metrics-kubernetes.scheduler-default
meta:
package:
name: kubernetes
version: 1.9.0
metricsets:
- scheduler
module: kubernetes
name: kubernetes-node-metrics
period: 10s
processors:
- add_fields:
fields:
labels:
component: kube-scheduler
tier: control-plane
namespace: kube-system
namespace_labels:
kubernetes_io/metadata_name: kube-system
namespace_uid: 03d6fd2f-7279-4db4-9a98-51e50bbe5c62
node:
hostname: kind-control-plane
labels:
beta_kubernetes_io/arch: amd64
beta_kubernetes_io/os: linux
kubernetes_io/arch: amd64
kubernetes_io/hostname: kind-control-plane
kubernetes_io/os: linux
node-role_kubernetes_io/control-plane: ""
node_kubernetes_io/exclude-from-external-load-balancers: ""
name: kind-control-plane
uid: b8d65d6b-61ed-49ef-9770-3b4f40a15a8a
pod:
ip: 172.19.0.2
name: kube-scheduler-kind-control-plane
uid: f028ad77-c82a-4f29-ba7e-2504d9b0beef
target: kubernetes
- add_fields:
fields:
cluster:
name: kind
url: kind-control-plane:6443
target: orchestrator
- add_fields:
fields:
dataset: kubernetes.scheduler
namespace: default
type: metrics
target: data_stream
- add_fields:
fields:
dataset: kubernetes.scheduler
target: event
- add_fields:
fields:
id: ""
snapshot: false
version: 8.3.0
target: elastic_agent
- add_fields:
fields:
id: ""
target: agent
ssl.verification_mode: none
----


== Example: Dynamic logs path

To set the log path of Pods dynamically in the configuration, use a variable in the
{agent} policy to return path information from the provider:

[source,yaml]
----
- name: container-log
id: container-log-${kubernetes.pod.name}-${kubernetes.container.id}
type: filestream
use_output: default
meta:
package:
name: kubernetes
version: 1.9.0
data_stream:
namespace: default
streams:
- data_stream:
dataset: kubernetes.container_logs
type: logs
prospector.scanner.symlinks: true
parsers:
- container: ~
paths:
- /var/log/containers/*${kubernetes.container.id}.log
----

The policy generated by this configuration will look similar to this for every pod inside the scope defined in the manifest:

[source,yaml]
----
- id: container-log-etcd-kind-control-plane-af311067a62fa5e4d6e5cb4d31e64c1c35d82fe399eb9429cd948d5495496819
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
index: logs-kubernetes.container_logs-default
meta:
package:
name: kubernetes
version: 1.9.0
name: container-log
parsers:
- container: null
paths:
- /var/log/containers/*af311067a62fa5e4d6e5cb4d31e64c1c35d82fe399eb9429cd948d5495496819.log
processors:
- add_fields:
fields:
id: af311067a62fa5e4d6e5cb4d31e64c1c35d82fe399eb9429cd948d5495496819
image:
name: registry.k8s.io/etcd:3.5.4-0
runtime: containerd
target: container
- add_fields:
fields:
container:
name: etcd
labels:
component: etcd
tier: control-plane
namespace: kube-system
namespace_labels:
kubernetes_io/metadata_name: kube-system
namespace_uid: 03d6fd2f-7279-4db4-9a98-51e50bbe5c62
node:
hostname: kind-control-plane
labels:
beta_kubernetes_io/arch: amd64
beta_kubernetes_io/os: linux
kubernetes_io/arch: amd64
kubernetes_io/hostname: kind-control-plane
kubernetes_io/os: linux
node-role_kubernetes_io/control-plane: ""
node_kubernetes_io/exclude-from-external-load-balancers: ""
name: kind-control-plane
uid: b8d65d6b-61ed-49ef-9770-3b4f40a15a8a
pod:
ip: 172.19.0.2
name: etcd-kind-control-plane
uid: 08970fcf-bb93-487e-b856-02399d81fb29
target: kubernetes
- add_fields:
fields:
cluster:
name: kind
url: kind-control-plane:6443
target: orchestrator
- add_fields:
fields:
dataset: kubernetes.container_logs
namespace: default
type: logs
target: data_stream
- add_fields:
fields:
dataset: kubernetes.container_logs
target: event
- add_fields:
fields:
id: ""
snapshot: false
version: 8.3.0
target: elastic_agent
- add_fields:
fields:
id: ""
target: agent
prospector.scanner.symlinks: true
type: filestream
----
Loading