Search code examples
kubernetesfabric8

kubectl get deploy deploymentname -o yaml equivalent in Fabric8 client


I've an existing deployment in my Kubernetes cluster. I want to read its deployment.yaml file from Kubernetes environment using fabric8 client.Functionality similar to this command - kubectl get deploy deploymentname -o yaml. Please help me to get its fabric8 Java client equivalent.

Objective : I want to get deployment.yaml for a resource and save it with me , perform some experiments in the Kubernetes environment and after the experiments done,I want to revert back to previous deployment. So I need to have deployment.yaml handy to roll back the operation. Please help.

Thanks, Sapna


Solution

  • You can get the yaml representation of an object with the Serialization#asYaml method.

    For example:

    System.out.println(Serialization.asYaml(client.apps().deployments().inNamespace("abc").withName("ms1").get()));