16 Jun 2022 04:09 PM
HI Team,
May I ask in a Kubernetes OneAgent deployment could the kubernetes.yaml can be separated into multiple files so that Ansible playbook [Python engine] is able to parse the YAML files correctly?
The background is I have a use case where due to security policy enforcement, all "kubectl apply" commands should be carried our using the Ansible playbooks. We tried to simply run the "kubectl apply .... kubernetes.yaml" for deploying Dynatrace (operator, oneagent and activegate) but the playbook was failed to complete. The Ansible log returned "expected a single document in the stream" error message. I googled the log message and it most likely due to the Python engine issue on parsing multiple YAML section in the single document.
Error message:
An unhandled exception occurred while templating '{{ lookup('file', application_config)|from_yaml }}'. Error was a <class 'yaml.composer.ComposerError'>, original message: expected a single document in the stream
2022-06-15 10:53:28 in "<unicode string>", line 1, column 1:
2022-06-15 10:53:28 apiVersion: apiextensions.k8s.io/v1
2022-06-15 10:53:28 ^
2022-06-15 10:53:28 but found another document
2022-06-15 10:53:28 in "<unicode string>", line 2739, column 1:
2022-06-15 10:53:28 ---
2022-06-15 10:53:28 ^
Also, if those CRD/ServiceAccounts/ClusterRoles/ClusterRoleBindings/etc. can be separated into different YAML files, may I ask if there is any particular sequence to apply them to the K8S cluster? Can I simple just copy and paste different sections (i.e. separated by the line ---) as separate files?
Thank you very much and looking forward to your help.
Best Regards,
Zero
Solved! Go to Solution.
17 Jun 2022 12:51 AM
Hey Zero,
I don't have an environment to test this on so maybe someone with actual experience doing this could have a better response BUT I do remember that when learning about Kubernetes you're able to break up and merge the YAML files and as long as they're still applied in order then it should not make a difference.
I also found in the Kubernetes documentation that resources are deployed in the order that they appear in the file. So if you do break the files up it would be best practice to apply them in the order that they were in. As you can see kubectl appy also accepts multiple -f arguments so you could still do it all at once but with multiple files.
This is the docs page that I'm referencing
https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/
Hopefully someone has a more definitive answer!
17 Jun 2022 01:41 AM
Thanks for the sharing. Customer and I also believe the behavior where section in a single YAML file are parsed in a top-down sequence. Try to see if Dynatrace owns a page to remind us if there is special ordering that we need to pay attention. Will proceed the file break down and test the deployment on a clean K8S cluster.
17 Jun 2022 06:05 AM
Raise and RFE and create a product idea explaining the business justification and technical requirement. Let those split yaml be officially verified by DT.
Its feasible but never know what amount of testing this would need.