cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Separate the single OneAgent kubernetes.yaml file into different YAML files.

zero_ho
Dynatrace Participant
Dynatrace Participant

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

3 REPLIES 3

Fin_Ubels
Dynatrace Champion
Dynatrace Champion

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/

Fin_Ubels_0-1655422867141.png


Hopefully someone has a more definitive answer!

zero_ho
Dynatrace Participant
Dynatrace Participant

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.

techean
Dynatrace Champion
Dynatrace Champion

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.

KG

Featured Posts