Separate output files of cdk8s synth

4/21/2021

The following code will create one yaml file dist/clusterip.k8s.yaml contains all my defines of deployment and statefulset, is there way to separate different files in output such as dist/clusterip.k8s.yaml and dist/statefulset.k8s.yaml?

class MyChart(Chart):
    def __init__(self, scope: Construct, id: str):
        super().__init__(scope, id)
        ClusterIp(self, 'clusterip')
        StateFulSet(self, 'statefulset')

app = App()
MyChart(app, "clusterip")
-- vumdao
cdk8s
kubernetes
python
yaml

1 Answer

1/24/2022

Maybe not exactly what you want to hear but cdk8s creates one output file per chart. So you could split resources over multiple charts within your app.

As your personal workaround you also could split the yaml documents per file on your own. When you already have started using Python, that should be simple as yaml.safe_load the output file, loop over all documents and yaml.safe_dump them again. Between load and dump you can organize things as you wish.

-- Thomas Steinbach
Source: StackOverflow