Skip to content

Instantly share code, notes, and snippets.

@iocanel
Last active August 29, 2015 14:26
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 iocanel/c4821ebe5367a2b9ee90 to your computer and use it in GitHub Desktop.
Save iocanel/c4821ebe5367a2b9ee90 to your computer and use it in GitHub Desktop.
An first draft at the Kubernetes Java DSL
//Instantiate the client
KubernetesClient client = new DefaultKubernetesClient();
//Create a service
Service myservice = ...;
client.services().inNamespace("fabric8").create(myservice);
//Create a service inline
Service jenkins = client.services().inNamespace("fabric8").createNew()
.withNewMetadata()
.withName("jenkins")
.addToLabels("component", "jenkins")
.endMetadata()
.done();
//List services
ServiceList serviceList = client.services().inNamespace("fabric8").list();
//Watch services
client.services().inNamespace("fabric8").watch(new Watcher<Service>() {
@Override
public void eventReceived(Action action, Service resource) {
logger.info("{}: {}", action, resource);
}
});
//Delete by label
Boolean deleted = client.services().withLabel("component", "jenkins").delete();
//Close client
client.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment