Skip to content

Instantly share code, notes, and snippets.

@johnlabarge
Created February 13, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlabarge/2f533fa29605c8f0d7ea7154ff4397cd to your computer and use it in GitHub Desktop.
Save johnlabarge/2f533fa29605c8f0d7ea7154ff4397cd to your computer and use it in GitHub Desktop.
Yaml Example with api version
package io.kubernetes.client.examples;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.models.V1PodBuilder;
import io.kubernetes.client.util.Yaml;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
/**
* A simple example of how to parse a Kubernetes object.
*
* <p>Easiest way to run this: mvn exec:java
* -Dexec.mainClass="io.kubernetes.client.examples.YamlExample"
*
* <p>From inside $REPO_DIR/examples
*/
public class YamlExample {
public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {
V1Pod pod =
new V1PodBuilder()
.withApiVersion("core/v1")
.withNewMetadata()
.withName("apod")
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName("www")
.withImage("nginx")
.withNewResources()
.withLimits(new HashMap<>())
.endResources()
.endContainer()
.endSpec()
.build();
// System.out.println(Yaml.dump(pod));
File f = new File("example_pod.yaml");
FileWriter writer = new FileWriter(f);
writer.write(Yaml.dump(pod));
writer.close();
Object yamlObject = Yaml.load(f);
// V1Service svc =
// new V1ServiceBuilder()
// .withNewMetadata()
// .withName("aservice")
// .endMetadata()
// .withNewSpec()
// .withSessionAffinity("ClientIP")
// .withType("NodePort")
// .addNewPort()
// .withProtocol("TCP")
// .withName("client")
// .withPort(8008)
// .withNodePort(8080)
// .withTargetPort(new IntOrString(8080))
// .endPort()
// .endSpec()
// .build();
//
//
//
// System.out.println(Yaml.dump(svc));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment