-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* adding first templates for onboarding * Update deploy/kubernetes/elastic-agent-kustomize/default/README.md Co-authored-by: Craig MacKenzie <[email protected]> * manifest update with make * removing package variables from makefile * adding note for echo -n flag * changing DATASTRAM_ID to ONBOARDING_ID --------- Co-authored-by: Craig MacKenzie <[email protected]> (cherry picked from commit eca8da7) Co-authored-by: Andrew Gizas <[email protected]>
- Loading branch information
1 parent
abed32e
commit dba6a86
Showing
21 changed files
with
324 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ KUSTOMIZE=elastic-agent-kustomize | |
KUSTOMIZE_DEFAULT=elastic-agent-kustomize/default | ||
KUSTOMIZE_KSM_AUTOSHARDING=elastic-agent-kustomize/ksm-autosharding | ||
|
||
# variable for processor for elastic-agent-standalone | ||
define ELASTIC_PROCESSOR | ||
processors:\n - add_fields:\n fields:\n onboarding_id: '%ONBOARDING_ID%' | ||
endef | ||
|
||
.PHONY: generate-k8s $(ALL) | ||
generate-k8s: $(ALL) | ||
|
||
|
@@ -95,14 +100,15 @@ 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) | ||
|
||
ifdef GENERATEKUSTOMIZE | ||
export ELASTIC_PROCESSOR | ||
$(ALL): | ||
@echo "Generating $@ kustomize-default files" | ||
@for f in $(shell ls $@/*.yaml); do \ | ||
@for f in $(shell ls $@/*.yaml | grep -v elastic-agent-standalone-daemonset-configmap); do \ | ||
cp -r $$f $(KUSTOMIZE_DEFAULT)/$@/base; \ | ||
done | ||
|
||
|
@@ -115,9 +121,13 @@ $(ALL): | |
|
||
mkdir -p $(KUSTOMIZE_KSM_AUTOSHARDING)/$@/extra/ | ||
sed -e "s/%VERSION%/${BEAT_VERSION}/g" -e "s/%BRANCH%/${BRANCH_VERSION}/g" -e "/name: elastic-agent-state/,+1 s/^/#/" -e "/path: \/var\/lib\/$@\/kube-system\/state/,+1 s/^/#/" $@/[email protected] > $(KUSTOMIZE_KSM_AUTOSHARDING)/$@/base/[email protected] | ||
sed -e "s/%VERSION%/${BEAT_VERSION}/g" -e "s/%BRANCH%/${BRANCH_VERSION}/g" -e "/name: elastic-agent-state/,+1 s/^/#/" -e "/path: \/var\/lib\/$@\/kube-system\/state/,+1 s/^/#/" $@/[email protected] > $(KUSTOMIZE_KSM_AUTOSHARDING)/$@/base/[email protected] | ||
|
||
sed -e "s/%VERSION%/${BEAT_VERSION}/g" -e "s/%BRANCH%/${BRANCH_VERSION}/g" -e "s/hostNetwork: true/hostNetwork: false/g" -e "s/DaemonSet/StatefulSet/g" -e "s/agent-node-datastreams/agent-ksm-datastreams/g" -e "/name: elastic-agent-state/,+1 s/^/#/" -e "/path: \/var\/lib\/$@\/kube-system\/state/,+1 s/^/#/" $@/[email protected] > $(KUSTOMIZE_KSM_AUTOSHARDING)/$@/extra/[email protected] | ||
|
||
@echo "Generating processor $$ELASTIC_PROCESSOR" | ||
sed -e "s/#<processors_placeholder>/$$ELASTIC_PROCESSOR/g" elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml > $(KUSTOMIZE_DEFAULT)/elastic-agent-standalone/base/elastic-agent-standalone-daemonset-configmap.yaml | ||
|
||
else | ||
echo "No KSM templates generated. Please run: GENERATEKUSTOMIZE=true make ci-create-kustomize " | ||
|
||
endif | ||
endif |
71 changes: 71 additions & 0 deletions
71
deploy/kubernetes/elastic-agent-kustomize/default/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Kustomize Templates | ||
|
||
The list below includes the official [kustomize](https://github.com/kubernetes-sigs/kustomize) templates to run them in Kubernetes: | ||
|
||
Agent Scenario | Description | ||
---- | ---- | ||
[Elastic Agent managed - Default ](./elastic-agent-managed/) | Default Elastic Agent managed by Fleet setup. Kube-state-metrics (KSM) is installed automatically. | ||
[Elastic Agent standalone Default ](./elastic-agent-standalone/) | Default Standalone Elastic Agent setup. Kube-state-metrics (KSM) is installed automatically. | ||
|
||
## Using above templates | ||
|
||
Users can clone this repository to use the provided kustomize templates. | ||
|
||
For *Managed Elastic Agent*, please update the following variables inside main kustomization.yaml: | ||
|
||
- %FLEET_URL%: Fleet Server URL to enroll the Elastic Agent into. FLEET_URL can be found in Kibana, go to Management > Fleet > Settings | ||
- %ENROLLMENT_TOKEN%: Elasticsearch API key used to [enroll Elastic Agents](https://www.elastic.co/guide/en/fleet/current/fleet-enrollment-tokens.html#fleet-enrollment-tokens) in Fleet. *This should be encoded as base64 value because it will be stored as Kubernetes secret* | ||
|
||
Eg. | ||
|
||
```yaml | ||
secretGenerator: | ||
- name: elastic-agent-creds | ||
literals: | ||
- enrollment_token=%ENROLLMENT_TOKEN% | ||
``` | ||
For *Standalone Elastic Agent*, please update the following secrets inside main [kustomization.yaml](./elastic-agent-managed/kustomization.yaml): | ||
- %ES_HOST%: The Elasticsearch host to communicate with | ||
- %API_KEY: The API Key with access privileges to connect to Elasticsearch. See [create-api-key-standalone-agent](https://www.elastic.co/guide/en/fleet/current/grant-access-to-elasticsearch.html#create-api-key-standalone-agent). *This should be encoded as base64 value because it will be stored as Kubernetes secret* | ||
- %CA_TRUSTED%: The ssl.ca_trusted_fingerprint in order the elastic agent to be able to trust the certificate authority of the Elasticsearch output. | ||
- %ONBOARDING_ID%: A string that will be added as a new field and will denote a specific installation. *By default, this will be added to state_pod dataset.* | ||
## Remote usage of kustomize templates | ||
Users can use following commands: | ||
Managed Elastic Agent: | ||
```bash | ||
❯ kubectl https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-maanged\?ref\=main | sed -e "s/JUVOUk9MTE1FTlRfVE9LRU4l/base64_ENCODED_ENROLLMENT_TOKEN/g" -e "s/%FLEET_URL%/https:\/\/localhost:9200/g" | kubectl apply -f- | ||
|
||
``` | ||
|
||
Standalone Elastic Agent: | ||
|
||
```bash | ||
kubectl kustomize https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone\?ref\=main | sed -e "s/JUFQSV9LRVkl/<base64_encoded_APIKEY>/g" -e "s/%ES_HOST%/https:\/\/localhost:9200/g" -e "s/%CA_TRUSTED%/ca_trusted_fingerprint/g" -e "s/%ONBOARDING_ID%/12345/g" | kubectl apply -f- | ||
``` | ||
|
||
Examples of Base64 encoded values: | ||
|
||
```bash | ||
❯ echo -n %API_KEY% | base64 | ||
JUFQSV9LRVkl | ||
|
||
echo -n %ENROLLMENT_TOKEN% | base64 | ||
JUVOUk9MTE1FTlRfVE9LRU4l | ||
|
||
❯ echo -n JUVOUk9MTE1FTlRfVE9LRU4l | base64 -D | ||
%ENROLLMENT_TOKEN%% | ||
``` | ||
|
||
NOTE: `echo -n` flag needs to be provided in order to have correct base64 encoding. The echo command adds an extra line by default which needs to be avoided. | ||
|
||
## Updating kustomize templates | ||
|
||
The included kustomize templates are being produced based on [Makefile](../../Makefile) by running: `GENERATEKUSTOMIZE=true make ci-create-kustomize` | ||
|
||
The current templates are using patches as defined [here](https://github.com/elastic/elastic-agent/blob/main/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-managed/kustomization.yaml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...elastic-agent-kustomize/default/elastic-agent-managed/environmental-variables-remove.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: elastic-agent | ||
namespace: kube-system | ||
labels: | ||
app: elastic-agent | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: elastic-agent | ||
template: | ||
metadata: | ||
labels: | ||
app: elastic-agent | ||
spec: | ||
containers: | ||
- name: elastic-agent | ||
env: | ||
- $patch: delete | ||
name: FLEET_ENROLLMENT_TOKEN | ||
- $patch: delete | ||
name: FLEET_URL |
19 changes: 19 additions & 0 deletions
19
...s/elastic-agent-kustomize/default/elastic-agent-managed/fleet-enrollment-token-patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: FLEET_ENROLLMENT_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: elastic-agent-creds | ||
key: enrollment_token | ||
|
||
|
||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: FLEET_URL | ||
valueFrom: | ||
configMapKeyRef: | ||
name: elastic-agent-configs | ||
key: host | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...oy/kubernetes/elastic-agent-kustomize/default/elastic-agent-standalone/api-key-patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: API_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: elastic-agent-creds | ||
key: api_key | ||
|
||
|
||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: ES_HOST | ||
valueFrom: | ||
configMapKeyRef: | ||
name: elastic-agent-configs | ||
key: host | ||
|
||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: CA_TRUSTED | ||
valueFrom: | ||
configMapKeyRef: | ||
name: elastic-agent-configs | ||
key: ca_trusted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...stic-agent-kustomize/default/elastic-agent-standalone/environmental-variables-remove.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: elastic-agent-standalone | ||
namespace: kube-system | ||
labels: | ||
app: elastic-agent-standalone | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: elastic-agent-standalone | ||
template: | ||
metadata: | ||
labels: | ||
app: elastic-agent-standalone | ||
spec: | ||
containers: | ||
- name: elastic-agent-standalone | ||
env: | ||
- $patch: delete | ||
name: API_KEY | ||
- $patch: delete | ||
name: ES_HOST |
Oops, something went wrong.