Fabric8's Kubernetes Client is using a generated model and DSL that has the exact same structure as as the JSON and YAML configuration.
So in order to create a Service instance that looks like:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "myservice"
},
"spec": {
"ports": [
{
"protocol": "TCP",
"port": 80,
"targetPort": 8080,
}
],
"selector": {
"key": "value1",
},¬
"portalIP": "172.30.234.134",
"type": "ClusterIP",
}
}
You can use the following code:
Service service = new ServiceBuilder()
.withNewMetadata()
.withName("myservice")
.endMetadata()
.withNewSpec()
.addNewPort()
.withProtocol("TCP")
.withPort(80)
.withNewTargetPort(8080)
.endPort()
.addToSelector("key1", "value1")
.withPortalIP("172.30.234.134")
.withType("ClusterIP")
.endSpec()
.build();
If don't need to hold a reference of the service object and you just want to create it, you can inline it like:
client.services().createNew()
.withNewMetadata()
.withName("myservice")
.endMetadata()
.withNewSpec()
.addNewPort()
.withProtocol("TCP")
.withPort(80)
.withNewTargetPort(8080)
.endPort()
.addToSelector("key1", "value1")
.withPortalIP("172.30.234.134")
.withType("ClusterIP")
.endSpec()
.done();