Skip to content

Commit 9d2c3c9

Browse files
[helm]: forward agent providers configuration for fleet mode (#5912)
* feat: forward agent providers configuration for fleet mode * feat: add fleet example
1 parent 3eedba2 commit 9d2c3c9

File tree

12 files changed

+432
-95
lines changed

12 files changed

+432
-95
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Example: Managed by Fleet Elastic Agent
2+
3+
In this example we deploy an Elastic Agent that is managed by [Fleet](https://www.elastic.co/guide/en/fleet/current/manage-agents-in-fleet.html).
4+
5+
## Prerequisites:
6+
1. Follow [this guide](https://www.elastic.co/guide/en/fleet/current/install-fleet-managed-elastic-agent.html#elastic-agent-installation-steps) to set up an agent policy and enroll an agent to it. Do not download any binary, from the proposed enrollment command just extract the Fleet URL (`--url=$FLEET_URL`) and Enrollment token (`--enrollment-token=$FLEET_TOKEN`).
7+
8+
## Run:
9+
10+
```console
11+
helm install elastic-agent ../../ \
12+
--set agent.fleet.enabled=true \
13+
--set agent.fleet.url=$FLEET_URL \
14+
--set agent.fleet.token=$FLEET_TOKEN \
15+
--set agent.fleet.preset=perNode
16+
-n kube-system
17+
```
18+
19+
## Validate:
20+
21+
1. [Optional] Install kube-state metrics if you want to see the KSM related metrics `kubectl apply -k https://github.com/kubernetes/kube-state-metrics`.
22+
2. Install Kubernetes integration to the agent policy that you created in Fleet. If you didn't install kube-state metrics from above, make sure to disable them in the integration.
23+
3. The Kibana `kubernetes`-related dashboards should start showing the respective info.
24+
25+
## Note:
26+
27+
In this example we deploy an Elastic Agent that is managed by Fleet using the built-in `perNode` preset (`DaemonSet`) targeting kubernetes monitoring. However, a user-defined agent `preset`, for different use cases, can be used as well, e.g. by using the following configuration:
28+
```yaml
29+
agent:
30+
fleet:
31+
enabled: true
32+
url: $FLEET_URL # replace with Fleet URL
33+
token: $FLEET_TOKEN # replace with Fleet Enrollment token
34+
preset: nginx
35+
presets:
36+
nginx:
37+
mode: deployment
38+
securityContext:
39+
runAsUser: 0
40+
rules:
41+
# minimum cluster role ruleset required by agent
42+
- apiGroups: [ "" ]
43+
resources:
44+
- nodes
45+
- namespaces
46+
- pods
47+
verbs:
48+
- get
49+
- watch
50+
- list
51+
- apiGroups: [ "apps" ]
52+
resources:
53+
- replicasets
54+
verbs:
55+
- get
56+
- list
57+
- watch
58+
- apiGroups: [ "batch" ]
59+
resources:
60+
- jobs
61+
verbs:
62+
- get
63+
- list
64+
- watch
65+
providers:
66+
kubernetes_leaderelection:
67+
enabled: false
68+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
agent:
2+
fleet:
3+
enabled: true
4+
url: http://localhost:8220
5+
token: fleetToken
6+
preset: nginx
7+
presets:
8+
nginx:
9+
mode: deployment
10+
securityContext:
11+
runAsUser: 0
12+
rules:
13+
# minimum cluster role ruleset required by agent
14+
- apiGroups: [ "" ]
15+
resources:
16+
- nodes
17+
- namespaces
18+
- pods
19+
verbs:
20+
- get
21+
- watch
22+
- list
23+
- apiGroups: [ "apps" ]
24+
resources:
25+
- replicasets
26+
verbs:
27+
- get
28+
- list
29+
- watch
30+
- apiGroups: [ "batch" ]
31+
resources:
32+
- jobs
33+
verbs:
34+
- get
35+
- list
36+
- watch
37+
providers:
38+
kubernetes_leaderelection:
39+
enabled: false
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
---
2+
# Source: elastic-agent/templates/agent/service-account.yaml
3+
apiVersion: v1
4+
kind: ServiceAccount
5+
metadata:
6+
name: agent-nginx-example
7+
namespace: "default"
8+
labels:
9+
helm.sh/chart: elastic-agent-0.0.1
10+
app.kubernetes.io/name: elastic-agent
11+
app.kubernetes.io/instance: example
12+
app.kubernetes.io/version: 9.0.0
13+
app.kubernetes.io/managed-by: Helm
14+
---
15+
# Source: elastic-agent/templates/agent/k8s/secret.yaml
16+
apiVersion: v1
17+
kind: Secret
18+
metadata:
19+
name: agent-nginx-example
20+
namespace: "default"
21+
labels:
22+
helm.sh/chart: elastic-agent-0.0.1
23+
app.kubernetes.io/name: elastic-agent
24+
app.kubernetes.io/instance: example
25+
app.kubernetes.io/version: 9.0.0
26+
app.kubernetes.io/managed-by: Helm
27+
stringData:
28+
29+
agent.yml: |-
30+
fleet:
31+
enabled: true
32+
providers:
33+
kubernetes_leaderelection:
34+
enabled: false
35+
---
36+
# Source: elastic-agent/templates/agent/cluster-role.yaml
37+
apiVersion: rbac.authorization.k8s.io/v1
38+
kind: ClusterRole
39+
metadata:
40+
name: agent-nginx-example-default
41+
labels:
42+
helm.sh/chart: elastic-agent-0.0.1
43+
app.kubernetes.io/name: elastic-agent
44+
app.kubernetes.io/instance: example
45+
app.kubernetes.io/version: 9.0.0
46+
app.kubernetes.io/managed-by: Helm
47+
rules:
48+
- apiGroups: [ "" ] # "" indicates the core API group
49+
resources:
50+
- nodes
51+
- namespaces
52+
- events
53+
- pods
54+
- services
55+
- configmaps
56+
- persistentvolumes
57+
- persistentvolumeclaims
58+
- persistentvolumeclaims/status
59+
- nodes/metrics
60+
- nodes/proxy
61+
- nodes/stats
62+
verbs:
63+
- get
64+
- watch
65+
- list
66+
- apiGroups:
67+
- storage.k8s.io
68+
resources:
69+
- storageclasses
70+
verbs:
71+
- get
72+
- watch
73+
- list
74+
- nonResourceURLs:
75+
- /metrics
76+
verbs:
77+
- get
78+
- watch
79+
- list
80+
- apiGroups: [ "coordination.k8s.io" ]
81+
resources:
82+
- leases
83+
verbs:
84+
- get
85+
- create
86+
- update
87+
- nonResourceURLs:
88+
- /healthz
89+
- /healthz/*
90+
- /livez
91+
- /livez/*
92+
- /metrics
93+
- /metrics/slis
94+
- /readyz
95+
- /readyz/*
96+
verbs:
97+
- get
98+
- apiGroups: [ "apps" ]
99+
resources:
100+
- replicasets
101+
- deployments
102+
- daemonsets
103+
- statefulsets
104+
verbs:
105+
- get
106+
- list
107+
- watch
108+
- apiGroups: [ "batch" ]
109+
resources:
110+
- jobs
111+
- cronjobs
112+
verbs:
113+
- get
114+
- list
115+
- watch
116+
- apiGroups:
117+
- ""
118+
resources:
119+
- nodes
120+
- namespaces
121+
- pods
122+
verbs:
123+
- get
124+
- watch
125+
- list
126+
- apiGroups:
127+
- apps
128+
resources:
129+
- replicasets
130+
verbs:
131+
- get
132+
- list
133+
- watch
134+
- apiGroups:
135+
- batch
136+
resources:
137+
- jobs
138+
verbs:
139+
- get
140+
- list
141+
- watch
142+
---
143+
# Source: elastic-agent/templates/agent/cluster-role-binding.yaml
144+
apiVersion: rbac.authorization.k8s.io/v1
145+
kind: ClusterRoleBinding
146+
metadata:
147+
name: agent-nginx-example-default
148+
labels:
149+
helm.sh/chart: elastic-agent-0.0.1
150+
app.kubernetes.io/name: elastic-agent
151+
app.kubernetes.io/instance: example
152+
app.kubernetes.io/version: 9.0.0
153+
app.kubernetes.io/managed-by: Helm
154+
subjects:
155+
- kind: ServiceAccount
156+
name: agent-nginx-example
157+
namespace: "default"
158+
roleRef:
159+
kind: ClusterRole
160+
name: agent-nginx-example-default
161+
apiGroup: rbac.authorization.k8s.io
162+
---
163+
# Source: elastic-agent/templates/agent/k8s/deployment.yaml
164+
apiVersion: apps/v1
165+
kind: Deployment
166+
metadata:
167+
name: agent-nginx-example
168+
namespace: "default"
169+
labels:
170+
helm.sh/chart: elastic-agent-0.0.1
171+
app.kubernetes.io/name: elastic-agent
172+
app.kubernetes.io/instance: example
173+
app.kubernetes.io/version: 9.0.0
174+
app.kubernetes.io/managed-by: Helm
175+
spec:
176+
selector:
177+
matchLabels:
178+
name: agent-nginx-example
179+
template:
180+
metadata:
181+
labels:
182+
name: agent-nginx-example
183+
annotations:
184+
checksum/config: ce25762427c9b6e207de5327b69be314f9d077db8138b7b241fd40f7b8a80aca
185+
spec:
186+
automountServiceAccountToken: true
187+
containers:
188+
- args:
189+
- -c
190+
- /etc/elastic-agent/agent.yml
191+
- -e
192+
env:
193+
- name: NODE_NAME
194+
valueFrom:
195+
fieldRef:
196+
fieldPath: spec.nodeName
197+
- name: POD_NAME
198+
valueFrom:
199+
fieldRef:
200+
fieldPath: metadata.name
201+
- name: STATE_PATH
202+
value: /usr/share/elastic-agent/state
203+
- name: FLEET_URL
204+
value: http://localhost:8220
205+
- name: FLEET_ENROLLMENT_TOKEN
206+
value: fleetToken
207+
- name: FLEET_INSECURE
208+
value: "false"
209+
- name: FLEET_ENROLL
210+
value: "1"
211+
image: docker.elastic.co/beats/elastic-agent:9.0.0-SNAPSHOT
212+
imagePullPolicy: IfNotPresent
213+
name: agent
214+
securityContext:
215+
runAsUser: 0
216+
volumeMounts:
217+
- mountPath: /usr/share/elastic-agent/state
218+
name: agent-data
219+
- mountPath: /etc/elastic-agent/agent.yml
220+
name: config
221+
readOnly: true
222+
subPath: agent.yml
223+
dnsPolicy: ClusterFirstWithHostNet
224+
serviceAccountName: agent-nginx-example
225+
volumes:
226+
- hostPath:
227+
path: /etc/elastic-agent/default/agent-nginx-example-managed/state
228+
type: DirectoryOrCreate
229+
name: agent-data
230+
- name: config
231+
secret:
232+
defaultMode: 292
233+
secretName: agent-nginx-example

0 commit comments

Comments
 (0)