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

Adding kustomize templates for k8s onboarding #4754

merged 42 commits into from
Jun 26, 2024

Conversation

gizas
Copy link
Contributor

@gizas gizas commented May 15, 2024

  • Enhancement

What does this PR do?

WHAT: Introduces the onboarding templates of kustomize for k8s observability
WHY: #4657

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

How to test this PR locally

  1. Clone this repo
  2. Change to directory elastic/elastic-agent/deploy/kubernetes
  3. Use makefile to generate templates
GENERATEKUSTOMIZE=true make ci-create-kustomize
  1. test the templates with
cd elastic-agent-kustomize/default
kubectl apply -k elastic-agent-managed
or 
kubectl apply -k elastic-agent-standalone

Examples of online references:

kubectl kustomize https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-managed\?ref\=kustomizepoc

kubectl kustomize https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-managed\?ref\=main

kubectl apply -k https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-managed\?ref\=v8.13.1

Testing for onboarding procedure

Managed:

❯ kubectl kustomize elastic-agent-kustomize/default/elastic-agent-managed/ | sed -e "s/JUVOUk9MTE1FTlRfVE9LRU4l/base64_ENCODED_ENROLLMENT_TOKEN/g" -e "s/%FLEET_URL%/https:\/\/localhost:9200/g" | kubectl apply -f-

Standalone

❯ kubectl kustomize elastic-agent-kustomize/default/elastic-agent-standalone/ | 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/%ELASTIC_AGENT_ID%/12345/g" | kubectl apply -f-

Eg.

❯ kubectl kustomize https://github.com/elastic/elastic-agent/deploy/kubernetes/elastic-agent-kustomize/default/elastic-agent-managed\?ref\=kustomizepoc |  sed -e 's/JUFQSV9LRVkl/JUFQSV9LRVkl/g' -e "s/%ES_HOST%/https:\/\/localhost:9200/g" -e "s/%CA_TRUSTED%/ca_trusted_fingerprint/g" -e "s/%ELASTIC_AGENT_ID%/12345/g" |  kubectl apply -f-

Note: API_KEY should be given as bas64 encoded values from Kibana

Base 64 encoding decding:

echo '${enrollment_token}' | base64
JHtlbnJvbGxtZW50X3Rva2VufQo=
❯ echo '${api_key}' | base64
JHthcGlfa2V5fQo=
> echo JHtlbnJvbGxtZW50X3Rva2VufQ== | base64 -D
${enrollment_token}

Images

Successful enrollement in managed

Screenshot 2024-05-15 at 5 31 11 PM

Successful Installation of kube-state-metrics and

kgp -n kube-system
NAME                                         READY   STATUS    RESTARTS       AGE
coredns-5d78c9869d-b6np9                     1/1     Running   6 (7d8h ago)   22d
coredns-5d78c9869d-p62sz                     1/1     Running   6 (7d8h ago)   22d
elastic-agent-tvskp                          1/1     Running   0              11s
etcd-kind-control-plane                      1/1     Running   0              7d8h
kindnet-qpxrb                                1/1     Running   6 (7d8h ago)   22d
kube-apiserver-kind-control-plane            1/1     Running   0              7d8h
kube-controller-manager-kind-control-plane   1/1     Running   6 (7d8h ago)   22d
kube-proxy-96hfl                             1/1     Running   6 (7d8h ago)   22d
kube-scheduler-kind-control-plane            1/1     Running   6 (7d8h ago)   22d
kube-state-metrics-5f89fb6d84-8f2sm          1/1     Running   0              11s

Related issues

@gizas gizas requested a review from constanca-m May 15, 2024 11:27
@mergify mergify bot assigned gizas May 15, 2024
Copy link
Contributor

mergify bot commented May 15, 2024

This pull request does not have a backport label. Could you fix it @gizas? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@constanca-m
Copy link
Contributor

constanca-m commented May 15, 2024

I am a bit confused. What is the different between default and onboarding directories?

@mykolaharmash
Copy link

mykolaharmash commented Jun 20, 2024

@gizas one other thing came up about the elastic agent version. Right now in the template, version is set to non-existing 8.15.0. Can we somehow ensure that we always have a valid version there, or alternatively expose it as well as a variable, so for onboarding use-case we can set it on our side?

@gizas
Copy link
Contributor Author

gizas commented Jun 20, 2024

@mykolaharmash the way it works is that the Makefile computes the agent image version based on this file:

const defaultBeatVersion = "8.15.0"

So all the daemonset file has the elastic-agent:8.15.0 inside. This is the only place where I see that this image exists

So i guess another sed like: sed -e "s/elastic-agent:8.15.0/elastic-agent:VERSION/g" can do the magic.

Also, I think this is only now a problem until we merge the PR. After that we wont have the problem and the CI will make sure that this is always correct. And the user can choose the version with the following use of ref:
kubectl kustomize elastic-agent-kustomize/default/elastic-agent-managed?ref=v8.15.1

@gizas
Copy link
Contributor Author

gizas commented Jun 20, 2024

Updating my answer above, I think needs to be mandatory for kibana UI onboarding to update the link like
kubectl kustomize <url>?ref=v8.15.1 always with the existing version of the system of the user. Otherwise we will use always the main branch and this might break in the periods where the version.go file is ahead from the latest released versiosn

@flash1293
Copy link

@gizas Just to make sure - is there an automation that there is a version of the template for every stack version? Or is this something that needs to be done manually? We should make sure that this won't break in the next version.

@gizas
Copy link
Contributor Author

gizas commented Jun 20, 2024

is there an automation that there is a version of the template for every stack version?

Yes as part of this PR, I have added this in the ci:
https://github.com/elastic/elastic-agent/pull/4754/files#diff-744561ff1e6cb54740e099862a03543c589ecd5416130dab47ce3c4f1b6130a1R32

@mykolaharmash
Copy link

Got it, thank you! I'll update the onboarding logic so that URL always has the version ref

@gizas
Copy link
Contributor Author

gizas commented Jun 21, 2024

@cmacknz or @blakerouse if no other objection can you please approve this? We will need one more to merge

Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@mykolaharmash
Copy link

mykolaharmash commented Jun 25, 2024

@gizas one more things about the Elastic Agent version, am I correct that even after your change is merged, we still need to wait for Agent v8.15.0 to be released in order to use the new template in onboarding? Because if we reference ref=8.14.1 it will have the old one, right?

@flash1293
Copy link

flash1293 commented Jun 25, 2024

Good point @mykolaharmash , ideally we could backport this so it will work for 8.14.x as well on serverless before the 8.15 release which is still some time in the future?

@gizas gizas added the backport-v8.14.0 Automated backport with mergify label Jun 25, 2024
@mergify mergify bot removed the backport-skip label Jun 25, 2024
@gizas
Copy link
Contributor Author

gizas commented Jun 25, 2024

@mykolaharmash I added backport-v8.14.0 label. Thanks!
I will check the backport

@elastic/elastic-agent-control-plane team can I have an approval please?

@pierrehilbert
Copy link
Contributor

@blakerouse / @andrzej-stencel could you please review here?

@gizas gizas merged commit eca8da7 into main Jun 26, 2024
15 checks passed
@gizas gizas deleted the kustomizepoc branch June 26, 2024 07:15
mergify bot pushed a commit that referenced this pull request Jun 26, 2024
* adding first templates for onboarding

* adding secrtegenerator with env

* adding readme for kustomize and updating ci script

* Update deploy/kubernetes/elastic-agent-kustomize/default/README.md

Co-authored-by: Craig MacKenzie <[email protected]>

* Update deploy/kubernetes/elastic-agent-kustomize/default/README.md

Co-authored-by: Craig MacKenzie <[email protected]>

* 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)
gizas added a commit that referenced this pull request Jun 26, 2024
* 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]>
mykolaharmash added a commit to elastic/kibana that referenced this pull request Jul 10, 2024
Depends on: elastic/elastic-agent#4754
Depends on: #186106
Closes: #182407

## Summary

Adds a Kubernetes onboarding quick start flow using `kubectl kustomize`
command.
![CleanShot 2024-06-18 at 15 10
27@2x](https://github.com/elastic/kibana/assets/793851/522d2481-6a0e-43d3-b9ef-d09ee9953b3c)

## How to test
1. Run Kibana and ES locally (make sure to expose ES on 0.0.0.0 so
elastic agent can reach it from within a container, I use this command
`yarn es snapshot --license trial -E
xpack.security.authc.api_key.enabled=true -E http.host=0.0.0.0`)
2. Setup a test cluster with
[minikube](https://minikube.sigs.k8s.io/docs/start/?arch=%2Fmacos%2Fx86-64%2Fstable%2Fbinary+download)
3. Open Kibana and navigate to the Onboarding screen
4. Make sure Kubernetes quick start card is visible under the
infrastructure category and click on it
5. Copy the command snippet
6. Paste the command into a terminal, but don't run it yet
7. Replace `localhost` in the command with you local IP `ipconfig
getifaddr en0`
8. In case elastic/elastic-agent#4754 was not
merged yet, you'd need to also clone the elastic-agent repo and replace
the template URL with a local path to the
`elastic-agent-kustomize/default/elastic-agent-standalone` folder.
9. Run the command and make sure all resources were created
10. Go back to Kibana, after ~1 minute UI should identify that the data
was ingested
11. Click on the cluster overview link and make sure it works

---------

Co-authored-by: Elastic Machine <[email protected]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 10, 2024
Depends on: elastic/elastic-agent#4754
Depends on: elastic#186106
Closes: elastic#182407

## Summary

Adds a Kubernetes onboarding quick start flow using `kubectl kustomize`
command.
![CleanShot 2024-06-18 at 15 10
27@2x](https://github.com/elastic/kibana/assets/793851/522d2481-6a0e-43d3-b9ef-d09ee9953b3c)

## How to test
1. Run Kibana and ES locally (make sure to expose ES on 0.0.0.0 so
elastic agent can reach it from within a container, I use this command
`yarn es snapshot --license trial -E
xpack.security.authc.api_key.enabled=true -E http.host=0.0.0.0`)
2. Setup a test cluster with
[minikube](https://minikube.sigs.k8s.io/docs/start/?arch=%2Fmacos%2Fx86-64%2Fstable%2Fbinary+download)
3. Open Kibana and navigate to the Onboarding screen
4. Make sure Kubernetes quick start card is visible under the
infrastructure category and click on it
5. Copy the command snippet
6. Paste the command into a terminal, but don't run it yet
7. Replace `localhost` in the command with you local IP `ipconfig
getifaddr en0`
8. In case elastic/elastic-agent#4754 was not
merged yet, you'd need to also clone the elastic-agent repo and replace
the template URL with a local path to the
`elastic-agent-kustomize/default/elastic-agent-standalone` folder.
9. Run the command and make sure all resources were created
10. Go back to Kibana, after ~1 minute UI should identify that the data
was ingested
11. Click on the cluster overview link and make sure it works

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 141e619)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.14.0 Automated backport with mergify Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants