<pre><code>public void runKubernetes() {
    KubernetesCluster k8sCluster = this.getKubernetesCluster("xyz-aks");
    System.out.println("___________________________________________");
    System.out.println("Kubernetes Cluster String: " + k8sCluster.name());

    DefaultKubernetesClient kubeclient = new DefaultKubernetesClient();
    System.out.println("Kube client Master URL :"+kubeclient.getMasterUrl());

    NodeList kubenodes = kubeclient.nodes().list();
    for (Node node : kubenodes.getItems()) {
        System.out.println( node.getKind() + " =&gt; " + node.getMetadata().getName() +": " + node.getMetadata().getClusterName());
    }
}
</code></pre>

<p>I get Client and nodes. Now, I have yaml file and I want to deploy that yaml (create service, deployment and pods) programatically. </p>

<p>I can do following </p>

<pre><code>kubectl create -f pod-sample.yaml 
</code></pre>

<p>but I want to do same thing using JAVA SDK.</p>

<p>I am using following java libraries for kubernetes:</p>

<pre><code>io.fabric8.kubernetes
</code></pre>

<p>I believe you can parse the YAML or JSON of the deployment definition. For example, for YAML you can use any of the Java libraries <a href="http://yaml.org/" rel="nofollow noreferrer">here</a></p>

<ul>
<li><a href="https://jvyaml.dev.java.net/" rel="nofollow noreferrer">JvYaml</a>             # Java port of RbYaml</li>
<li><a href="http://www.snakeyaml.org/" rel="nofollow noreferrer">SnakeYAML</a>          # Java 5 / YAML 1.1</li>
<li><a href="http://yamlbeans.sourceforge.net/" rel="nofollow noreferrer">YamlBeans</a>          # To/from JavaBeans</li>
<li><a href="http://jyaml.sourceforge.net/" rel="nofollow noreferrer">JYaml</a>              # Original Java Implementation</li>
<li><a href="https://www.github.com/decorators-squad/camel" rel="nofollow noreferrer">Camel</a>              # YAML 1.2 for Java. A user-friendly OOP library.</li>
</ul>

<p><a href="https://github.com/FasterXML/jackson" rel="nofollow noreferrer">Jackson</a> seems to be the more popular for JSON which also supports a YAML extension.</p>

<p>Then once you parse say the name, for example to create a service:</p>

<pre><code>Service myservice = client.services().inNamespace(parsedNamespaceStr).createNew()
                     .withNewMetadata()
                       .withName(parsedServiceName)
                       .addToLabels(parsedLabel1, parseLabel2)
                     .endMetadata()
                     .done();
</code></pre>
