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

Adding kustomize templates for k8s onboarding #4754

Merged
merged 42 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d61eb2d
adding first templates for onboarding
gizas May 15, 2024
48ffca8
adding fragment
gizas May 15, 2024
9ae2b17
adding first script geenrator
gizas May 15, 2024
0f6ca32
adding pathces for environmental variables
gizas May 16, 2024
1f1f28a
changing image for tests
gizas May 16, 2024
4b7e7e8
removing unneeded env file
gizas May 16, 2024
c34f1d4
adding envs in secret
gizas May 16, 2024
703188c
adding envs in secret
gizas May 16, 2024
27ff651
removing secret generator
gizas May 16, 2024
7882051
adding secrtegenerator with env
gizas May 16, 2024
af5d49f
adding secrtegenerator with env
gizas May 16, 2024
516433f
correcting typos
gizas May 16, 2024
01afc64
adding readme for kustomize and updating ci script
gizas May 16, 2024
b852604
adding readme for kustomize and updating ci script
gizas May 16, 2024
ec6b989
updating readme and fixing patching for standalone
gizas May 17, 2024
738d763
updating readme
gizas May 17, 2024
3102c97
updating standalone template
gizas May 17, 2024
2452d8d
updating standalone template
gizas May 17, 2024
f2d7502
updating readme
gizas May 17, 2024
c4f60df
updating readme
gizas May 17, 2024
0979c9f
updating readme
gizas May 17, 2024
6163e90
fixing correct key for standalone secret
gizas May 17, 2024
7e22d7c
fixing correct key for standalone secret
gizas May 17, 2024
f271da2
adding makefile for agent id processor
gizas May 21, 2024
f24d61e
adding makefile for agent id processor
gizas May 21, 2024
f31c442
adding config maps for secrets
gizas May 21, 2024
ec22f90
adding updates on README
gizas May 21, 2024
8ab9250
Merge branch 'main' into kustomizepoc
gizas Jun 12, 2024
111d8d0
changing elastic_agent_id to dataset_id
gizas Jun 12, 2024
50351ad
Merge branch 'main' into kustomizepoc
gizas Jun 17, 2024
487acad
Update deploy/kubernetes/elastic-agent-kustomize/default/README.md
gizas Jun 18, 2024
a95dd4e
Update deploy/kubernetes/elastic-agent-kustomize/default/README.md
gizas Jun 18, 2024
fa15a97
Update deploy/kubernetes/elastic-agent-kustomize/default/README.md
gizas Jun 18, 2024
d1a2837
Merge branch 'main' into kustomizepoc
gizas Jun 18, 2024
0010ae3
Merge branch 'main' into kustomizepoc
gizas Jun 19, 2024
3c29f32
manifest update with make
gizas Jun 19, 2024
d9e1f01
removing package variables from makefile
gizas Jun 19, 2024
f1635b6
adding note for echo -n flag
gizas Jun 19, 2024
89cc0d9
changing DATASTRAM_ID to ONBOARDING_ID
gizas Jun 20, 2024
a6dba3d
Merge branch 'main' into kustomizepoc
gizas Jun 20, 2024
37342a8
Merge branch 'main' into kustomizepoc
gizas Jun 21, 2024
8c56fef
Merge branch 'main' into kustomizepoc
gizas Jun 25, 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
32 changes: 32 additions & 0 deletions changelog/fragments/1715773969-kustomize-onboarding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: enhancement

# Change summary; a 80ish characters long description of the change.
summary: kustomize templates using default manifests for k8s onboarding

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
24 changes: 23 additions & 1 deletion deploy/kubernetes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ELASTIC_AGENT_BRANCH=update-k8s-templates-$(shell date "+%Y%m%d%H%M%S")
KUSTOMIZE=elastic-agent-kustomize
KUSTOMIZE_DEFAULT=elastic-agent-kustomize/default
KUSTOMIZE_KSM_AUTOSHARDING=elastic-agent-kustomize/ksm-autosharding
KUSTOMIZE_DEFAULT_ONBOARDING=elastic-agent-kustomize/onboarding/default
constanca-m marked this conversation as resolved.
Show resolved Hide resolved


.PHONY: generate-k8s $(ALL)
generate-k8s: $(ALL)
Expand Down Expand Up @@ -95,7 +97,7 @@ else
endif


## ci-create-kustomize-default : Create default kustomize folder
## ci-create-kustomize : Create default kustomize folder
.PHONY: ci-create-kustomize $(ALL)
ci-create-kustomize: $(ALL)

Expand All @@ -120,4 +122,24 @@ $(ALL):
else
echo "No KSM templates generated. Please run: GENERATEKUSTOMIZE=true make ci-create-kustomize "

endif


## ci-create-kustomize-onboarding : Create default kustomize folder only for onboarding
.PHONY: ci-create-kustomize-onboarding $(ALL)
ci-create-kustomize-onboarding: $(ALL)

ifdef GENERATEKUSTOMIZE
$(ALL):
@echo "Generating $@ kustomize-default files"
@for f in $(shell ls $@/*.yaml); do \
cp -r $$f $(KUSTOMIZE_DEFAULT_ONBOARDING)/$@/base; \
done

sed -e "s/%VERSION%/${BEAT_VERSION}/g" -e "s/%BRANCH%/${BRANCH_VERSION}/g" $@/[email protected] > $(KUSTOMIZE_DEFAULT_ONBOARDING)/$@/base/[email protected]


else
echo "No KSM templates generated. Please run: GENERATEKUSTOMIZE=true make ci-create-kustomize-onboarding "

endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ spec:
# Uncomment if using hints feature
gizas marked this conversation as resolved.
Show resolved Hide resolved
#initContainers:
# - name: k8s-templates-downloader
# image: busybox:1.28
# command: ['sh']
# image: docker.elastic.co/beats/elastic-agent:%VERSION%
# command: ['bash']
# args:
# - -c
# - >-
# mkdir -p /etc/elastic-agent/inputs.d &&
# wget -O - https://github.com/elastic/elastic-agent/archive/main.tar.gz | tar xz -C /etc/elastic-agent/inputs.d --strip=5 "elastic-agent-main/deploy/kubernetes/elastic-agent-standalone/templates.d"
# mkdir -p /usr/share/elastic-agent/state/inputs.d &&
# curl -sL https://github.com/elastic/elastic-agent/archive/%BRANCH%.tar.gz | tar xz -C /usr/share/elastic-agent/state/inputs.d --strip=5 "elastic-agent-%BRANCH%/deploy/kubernetes/elastic-agent-standalone/templates.d"
# securityContext:
# runAsUser: 0
# volumeMounts:
# - name: external-inputs
# mountPath: /etc/elastic-agent/inputs.d
# - name: elastic-agent-state
# mountPath: /usr/share/elastic-agent/state
containers:
- name: elastic-agent-standalone
image: docker.elastic.co/beats/elastic-agent:8.8.1
image: docker.elastic.co/beats/elastic-agent:%VERSION%
args: ["-c", "/etc/elastic-agent/agent.yml", "-e"]
env:
# The basic authentication username used to connect to Elasticsearch
Expand All @@ -61,9 +63,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: STATE_PATH
value: "/etc/elastic-agent"
# The following ELASTIC_NETINFO:false variable will disable the netinfo.enabled option of add-host-metadata processor. This will remove fields host.ip and host.mac.
# The following ELASTIC_NETINFO:false variable will disable the netinfo.enabled option of add-host-metadata processor. This will remove fields host.ip and host.mac.
# For more info: https://www.elastic.co/guide/en/beats/metricbeat/current/add-host-metadata.html
- name: ELASTIC_NETINFO
value: "false"
Expand Down Expand Up @@ -96,9 +96,6 @@ spec:
mountPath: /etc/elastic-agent/agent.yml
readOnly: true
subPath: agent.yml
# Uncomment if using hints feature
#- name: external-inputs
# mountPath: /etc/elastic-agent/inputs.d
- name: proc
mountPath: /hostfs/proc
readOnly: true
Expand Down Expand Up @@ -129,9 +126,6 @@ spec:
configMap:
defaultMode: 0640
name: agent-node-datastreams
# Uncomment if using hints feature
#- name: external-inputs
# emptyDir: {}
- name: proc
hostPath:
path: /proc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# For more information https://www.elastic.co/guide/en/fleet/current/running-on-kubernetes-managed-by-fleet.html
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: elastic-agent
namespace: kube-system
gizas marked this conversation as resolved.
Show resolved Hide resolved
labels:
app: elastic-agent
spec:
selector:
matchLabels:
app: elastic-agent
template:
metadata:
labels:
app: elastic-agent
spec:
# Tolerations are needed to run Elastic Agent on Kubernetes control-plane nodes.
# Agents running on control-plane nodes collect metrics from the control plane components (scheduler, controller manager) of Kubernetes
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
- key: node-role.kubernetes.io/master
effect: NoSchedule
serviceAccountName: elastic-agent
hostNetwork: true
# 'hostPID: true' enables the Elastic Security integration to observe all process exec events on the host.
# Sharing the host process ID namespace gives visibility of all processes running on the same host.
hostPID: true
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: elastic-agent
image: docker.elastic.co/beats/elastic-agent:8.15.0
env:
# Set to 1 for enrollment into Fleet server. If not set, Elastic Agent is run in standalone mode
- name: FLEET_ENROLL
value: "1"
# Set to true to communicate with Fleet with either insecure HTTP or unverified HTTPS
- name: FLEET_INSECURE
value: "false"
# Fleet Server URL to enroll the Elastic Agent into
# FLEET_URL can be found in Kibana, go to Management > Fleet > Settings
- name: FLEET_URL
value: "https://fleet-server:8220"
# Elasticsearch API key used to enroll Elastic Agents in Fleet (https://www.elastic.co/guide/en/fleet/current/fleet-enrollment-tokens.html#fleet-enrollment-tokens)
# If FLEET_ENROLLMENT_TOKEN is empty then KIBANA_HOST, KIBANA_FLEET_USERNAME, KIBANA_FLEET_PASSWORD are needed
- name: FLEET_ENROLLMENT_TOKEN
value: "token-id"
- name: KIBANA_HOST
value: "http://kibana:5601"
# The basic authentication username used to connect to Kibana and retrieve a service_token to enable Fleet
- name: KIBANA_FLEET_USERNAME
value: "elastic"
# The basic authentication password used to connect to Kibana and retrieve a service_token to enable Fleet
- name: KIBANA_FLEET_PASSWORD
value: "changeme"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
# The following ELASTIC_NETINFO:false variable will disable the netinfo.enabled option of add-host-metadata processor. This will remove fields host.ip and host.mac.
# For more info: https://www.elastic.co/guide/en/beats/metricbeat/current/add-host-metadata.html
- name: ELASTIC_NETINFO
value: "false"
securityContext:
runAsUser: 0
# The following capabilities are needed for 'Defend for containers' integration (cloud-defend)
# If you are using this integration, please uncomment these lines before applying.
#capabilities:
# add:
# - BPF # (since Linux 5.8) allows loading of BPF programs, create most map types, load BTF, iterate programs and maps.
# - PERFMON # (since Linux 5.8) allows attaching of BPF programs used for performance metrics and observability operations.
# - SYS_RESOURCE # Allow use of special resources or raising of resource limits. Used by 'Defend for Containers' to modify 'rlimit_memlock'
########################################################################################
# The following capabilities are needed for Universal Profiling.
# More fine graded capabilities are only available for newer Linux kernels.
# If you are using the Universal Profiling integration, please uncomment these lines before applying.
#procMount: "Unmasked"
#privileged: true
#capabilities:
# add:
# - SYS_ADMIN
resources:
limits:
memory: 700Mi
requests:
cpu: 100m
memory: 400Mi
volumeMounts:
- name: proc
mountPath: /hostfs/proc
readOnly: true
- name: cgroup
mountPath: /hostfs/sys/fs/cgroup
readOnly: true
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
- name: varlog
mountPath: /var/log
readOnly: true
- name: etc-full
mountPath: /hostfs/etc
readOnly: true
- name: var-lib
mountPath: /hostfs/var/lib
readOnly: true
- name: etc-mid
mountPath: /etc/machine-id
readOnly: true
- name: sys-kernel-debug
mountPath: /sys/kernel/debug
- name: elastic-agent-state
mountPath: /usr/share/elastic-agent/state
# If you are using the Universal Profiling integration, please uncomment these lines before applying.
#- name: universal-profiling-cache
# mountPath: /var/cache/Elastic
volumes:
- name: proc
hostPath:
path: /proc
- name: cgroup
hostPath:
path: /sys/fs/cgroup
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
- name: varlog
hostPath:
path: /var/log
# The following volumes are needed for Cloud Security Posture integration (cloudbeat)
# If you are not using this integration, then these volumes and the corresponding
# mounts can be removed.
- name: etc-full
hostPath:
path: /etc
- name: var-lib
hostPath:
path: /var/lib
# Mount /etc/machine-id from the host to determine host ID
# Needed for Elastic Security integration
- name: etc-mid
hostPath:
path: /etc/machine-id
type: File
# Needed for 'Defend for containers' integration (cloud-defend) and Universal Profiling
# If you are not using one of these integrations, then these volumes and the corresponding
# mounts can be removed.
- name: sys-kernel-debug
hostPath:
path: /sys/kernel/debug
# Mount /var/lib/elastic-agent-managed/kube-system/state to store elastic-agent state
# Update 'kube-system' with the namespace of your agent installation
- name: elastic-agent-state
hostPath:
path: /var/lib/elastic-agent-managed/kube-system/state
type: DirectoryOrCreate
# Mount required for Universal Profiling.
# If you are using the Universal Profiling integration, please uncomment these lines before applying.
#- name: universal-profiling-cache
# hostPath:
# path: /var/cache/Elastic
# type: DirectoryOrCreate
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: elastic-agent
subjects:
- kind: ServiceAccount
name: elastic-agent
namespace: kube-system
roleRef:
kind: ClusterRole
name: elastic-agent
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
namespace: kube-system
name: elastic-agent
subjects:
- kind: ServiceAccount
name: elastic-agent
namespace: kube-system
roleRef:
kind: Role
name: elastic-agent
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: elastic-agent-kubeadm-config
namespace: kube-system
subjects:
- kind: ServiceAccount
name: elastic-agent
namespace: kube-system
roleRef:
kind: Role
name: elastic-agent-kubeadm-config
apiGroup: rbac.authorization.k8s.io
Loading
Loading