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

[helm] support using user-created serviceAccount and clusterRole #5593

Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 0 additions & 18 deletions deploy/helm/elastic-agent/examples/eck/rendered/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
---
# Source: elastic-agent/templates/agent/service-account.yaml
apiVersion: v1
Expand All @@ -26,8 +24,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
---
# Source: elastic-agent/templates/agent/service-account.yaml
apiVersion: v1
Expand All @@ -41,8 +37,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
---
# Source: elastic-agent/templates/agent/eck/secret.yaml
apiVersion: v1
Expand Down Expand Up @@ -577,8 +571,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
rules:
- apiGroups: [ "" ] # "" indicates the core API group
resources:
Expand Down Expand Up @@ -702,8 +694,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
rules:
- apiGroups: [ "" ] # "" indicates the core API group
resources:
Expand Down Expand Up @@ -936,8 +926,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
rules:
- apiGroups: [ "" ] # "" indicates the core API group
resources:
Expand Down Expand Up @@ -1019,8 +1007,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
subjects:
- kind: ServiceAccount
name: agent-clusterwide-example
Expand All @@ -1041,8 +1027,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
subjects:
- kind: ServiceAccount
name: agent-ksmsharded-example
Expand All @@ -1063,8 +1047,6 @@ metadata:
app.kubernetes.io/instance: example
app.kubernetes.io/version: 9.0.0
app.kubernetes.io/managed-by: Helm
annotations:
eck.k8s.elastic.co/license: basic
subjects:
- kind: ServiceAccount
name: agent-pernode-example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ agent:
mode: deployment
securityContext:
runAsUser: 0
rules:
# minimum cluster role ruleset required by agent
- apiGroups: [ "" ]
resources:
- nodes
- namespaces
- pods
verbs:
- get
- watch
- list
- apiGroups: [ "apps" ]
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups: [ "batch" ]
resources:
- jobs
verbs:
- get
- list
- watch
serviceAccount:
create: true
clusterRole:
create: true
rules:
# minimum cluster role ruleset required by agent
- apiGroups: [ "" ]
resources:
- nodes
- namespaces
- pods
verbs:
- get
- watch
- list
- apiGroups: [ "apps" ]
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups: [ "batch" ]
resources:
- jobs
verbs:
- get
- list
- watch
providers:
kubernetes_leaderelection:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,35 @@ agent:
mode: deployment
securityContext:
runAsUser: 0
rules:
# minimum cluster role ruleset required by agent
- apiGroups: [ "" ]
resources:
- nodes
- namespaces
- pods
verbs:
- get
- watch
- list
- apiGroups: [ "apps" ]
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups: [ "batch" ]
resources:
- jobs
verbs:
- get
- list
- watch
serviceAccount:
create: true
clusterRole:
create: true
rules:
# minimum cluster role ruleset required by agent
- apiGroups: [ "" ]
resources:
- nodes
- namespaces
- pods
verbs:
- get
- watch
- list
- apiGroups: [ "apps" ]
resources:
- replicasets
verbs:
- get
- list
- watch
- apiGroups: [ "batch" ]
resources:
- jobs
verbs:
- get
- list
- watch
providers:
kubernetes_leaderelection:
enabled: false
37 changes: 37 additions & 0 deletions deploy/helm/elastic-agent/examples/user-cluster-role/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Example: Kubernetes Integration with User-created cluster role

In this example we define a `nginx` custom integration alongside a custom agent preset defined in [agent-nginx-values.yaml](agent-nginx-values.yaml) including the use of a user-created cluster role. Note that the user is responsible for assigning the correct permissions to the cluster role.

## Prerequisites:
1. A k8s secret that contains the connection details to an Elasticsearch cluster such as the URL and the API key ([Kibana - Creating API Keys](https://www.elastic.co/guide/en/kibana/current/api-keys.html)):
```console
kubectl create secret generic es-api-secret \
--from-literal=api_key=... \
--from-literal=url=...
```

2. `nginx` integration assets are installed through Kibana

3. Create a cluster role.

```console
kubectl create clusterrole user-cr --verb=get,list,watch --resource=pods,namespaces,nodes,replicasets,jobs
```

## Run:
1. Install Helm chart
```console
helm install elastic-agent ../../ \
-f ./agent-nginx-values.yaml \
--set outputs.default.type=ESSecretAuthAPI \
--set outputs.default.secretName=es-api-secret
```

2. Install the nginx deployment
```console
kubectl apply -f ./nginx.yaml
```

## Validate:

1. The Kibana `nginx`-related dashboards should start showing nginx related data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
kubernetes:
enabled: false

extraIntegrations:
nginx/metrics:
id: nginx/metrics-nginx-69240207-6fcc-4d19-aee3-dbf716e3bb0f
preset: nginx
name: nginx-1
revision: 1
type: nginx/metrics
use_output: default
meta:
package:
name: nginx
version: 1.19.1
data_stream:
namespace: default
package_policy_id: 69240207-6fcc-4d19-aee3-dbf716e3bb0f
streams:
- id: nginx/metrics-nginx.stubstatus-69240207-6fcc-4d19-aee3-dbf716e3bb0f
data_stream:
dataset: nginx.stubstatus
type: metrics
metricsets:
- stubstatus
hosts:
- 'http://nginx.default.svc.cluster.local:80'
tags:
- nginx-stubstatus
period: 10s
server_status_path: /nginx_status

agent:
presets:
nginx:
mode: deployment
securityContext:
runAsUser: 0
serviceAccount:
create: true
clusterRole:
create: false
name: user-cr
providers:
kubernetes_leaderelection:
enabled: false
Loading