Create kubernetes that manages pods in java

0 votes

I am looking to create a Service that manages a pod with a certain label on a certain port. Can you give me some example because i'm sure there is a way to do this.

Sep 5, 2018 in Kubernetes by Hannah
• 14,080 points
26 views

1 answer to this question.

0 votes

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();
answered Sep 5, 2018 by Kalgi
• 37,320 points

Related Questions In Kubernetes

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
1,141 views
+3 votes
1 answer
0 votes
2 answers
0 votes
2 answers

Restart pods when configmap updates in Kubernetes?

Use Deployments, and consider your ConfigMaps to ...READ MORE

answered Aug 31, 2018 in Kubernetes by Nilesh
• 6,900 points
2,854 views